-
Notifications
You must be signed in to change notification settings - Fork 0
/
htmlexercises2.html
324 lines (296 loc) · 13 KB
/
htmlexercises2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
---
layout: default
title: HTML Exercises 2
---
<button id="openbtn" class="openbtn" onclick="openNav()">☰</button>
<div class="container-fluid">
<div class="row">
<!-- Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/js/bootstrap.min.js"></script>
<div class="col-md-9">
<h1 class="text-center mb-5">HTML Tag Examples and Exercises - Part 2</h1>
<h2>Ordered List (ol) tag</h2>
<pre><code>
<ol>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ol>
</code> </pre>
<ol>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ol>
<p>What tag is used to create an ordered list?</p>
<input type="text" id="answer1">
<button >Check Answer</button>
<p id="result1"></p>
<pre><code>
<ol start="2" type="I">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ol>
</code> </pre>
<ol start="2" type="I">
<li value="1">Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ol>
<p>What attributes can be used with the ordered list tag?</p>
<input type="text" id="answer1_5">
<button onclick="checkAnswer1_5()">Check Answer</button>
<p id="result1_5"></p>
<h2>Unordered List (ul) tag</h2>
<pre><code>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</code> </pre>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
<p>What tag is used to create an unordered list?</p>
<input type="text" id="answer2">
<button onclick="checkAnswer2()">Check Answer</button>
<p id="result2"></p>
<pre><code>
<ul style="list-style-type: square;">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</code> </pre>
<ul style="list-style-type: square;">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
<p>What attribute can be used to change the bullet style of an unordered list?</p>
<input type="text" id="answer2_5">
<button onclick="checkAnswer2_5()">Check Answer</button>
<p id="result2_5"></p>
<h2>Table (table) tag</h2>
<pre><code>
<table>
<thead>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 1, Cell 1</td>
<td>Row 1, Cell 2</td>
</tr>
<tr>
<td>Row 2, Cell 1</td>
<td>Row 2, Cell 2</td>
</tr>
</tbody>
</table>
</code></pre>
<table border="1 solid">
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>Row 1, Cell 1</td>
<td>Row 1, Cell 2</td>
</tr>
<tr>
<td>Row 2, Cell 1</td>
<td>Row 2, Cell 2</td>
</tr>
</table>
<p>What tag is used to create a table?</p>
<input type="text" id="answer3">
<button onclick="checkAnswer3()">Check Answer</button>
<p id="result3"></p>
<table border="1 solid">
<caption>Sample Table</caption>
<thead>
<tr>
<th>Header 1</th>
<th>Header 2</th>
<th>Header 3</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2">Row 1, Cell 1</td>
<td>Row 1, Cell 2</td>
<td>Row 1, Cell 3</td>
</tr>
<tr>
<td>Row 2, Cell 2</td>
<td>Row 2, Cell 3</td>
</tr>
<tr>
<td>Row 3, Cell 1</td>
<td colspan="2">Row 3, Cell 2</td>
</tr>
</tbody>
</table>
<p>What attributes can be used with the table tag to specify the table structure?</p>
<input type="text" id="answer3_5">
<button onclick="checkAnswer3_5()">Check Answer</button>
<p id="result3_5"></p>
<h2>Horizontal Rule (hr) tag</h2>
<p><strong>hr</strong> is an HTML element used to insert a horizontal rule, which is a visual divider between sections of content. It is a self-closing tag that does not require a closing tag. The hr element creates a line across the entire width of the containing element by default. It is often used to separate different sections of a web page, such as paragraphs, images, or other content.</p>
<pre><code>
<hr>
<div>
<hr>
</div>
<br>
<div style="width: 50%;">
<hr>
</div>
</code></pre>
<hr>
<div style="padding: 20px; border: 1px solid red;">
<hr>
</div>
<br>
<div style="padding: 20px; border: 1px solid red; width: 50%;">
<hr>
</div>
<!-- <p>What tag is used to create a container for grouping HTML elements?</p>
<input type="text" id="answer4">
<button onclick="checkAnswer4()">Check Answer</button>
<p id="result4"></p> -->
<br>
<h2>Div (div) tag</h2>
<p><strong>div</strong> element is a block-level container element. This means that it takes up the full width of its parent element and creates a new line before and after its contents. It is <em>typically used</em> to group larger sections of content together, such as entire sections of a web page, or to apply styles to a group of elements.</p>
<pre><code>
<div>
<p>This is a paragraph inside a div tag.</p>
</div>
</code></pre>
<div style="background-color: lightblue; padding: 20px; border: 1px solid red;">
<p style="border: 1px solid blueviolet">This is a paragraph inside a div tag.</p>
</div>
<p>What tag is used to create a container for grouping HTML elements?</p>
<input type="text" id="answer4">
<button onclick="checkAnswer4()">Check Answer</button>
<p id="result4"></p>
<h2>Span (span) tag</h2>
<p><strong>span</strong> element is an inline container element. This means that it only takes up as much width as necessary to contain its contents, and does not create new lines before or after its contents. It is <em>typically used</em> to group smaller pieces of content together within a larger block-level element, or to apply styles to a specific portion of text within a block of text.</p>
<pre><code>
<p>This is some <span style="color: red;">text</span> inside a paragraph tag.</p>
</code></pre>
<p>This is some <span style="color: red;">text</span> inside a paragraph tag.</p>
<p>What tag is used to apply styles to a specific part of an HTML element?</p>
<input type="text" id="answer5">
<button onclick="checkAnswer5()">Check Answer</button>
<p id="result5"></p>
<p style="text-align: center; color: black;">© 2023 Made with 🖤 by <strong>Vikas Bandaru</strong></p>
</div>
</div>
</div>
<script>
function checkAnswer1_5() {
var answer1 = document.getElementById("answer1_5").value.toLowerCase();
if (answer1 === "start" || answer1 === "type" || answer1 === "value") {
document.getElementById("result1_5").innerHTML = "Correct!";
document.getElementById("result1_5").style.color = "green";
} else {
document.getElementById("result1_5").innerHTML = "Incorrect. Learn about ol tag attributes and try again.";
document.getElementById("result1_5").style.color = "red";
}
}
function checkAnswer2_5() {
var answer2 = document.getElementById("answer2_5").value.toLowerCase();
if (answer2 === "style") {
document.getElementById("result2_5").innerHTML = "Correct!";
document.getElementById("result2_5").style.color = "green";
} else {
document.getElementById("result2_5").innerHTML = "Incorrect. Learn about ul tag list item styling and try again.";
document.getElementById("result2_5").style.color = "red";
}
}
function checkAnswer3_5() {
var answer3 = document.getElementById("answer3_5").value.toLowerCase();
if (answer3 === "border" || answer3 === "rowspan" || answer3 === "colspan") {
document.getElementById("result3_5").innerHTML = "Correct!";
document.getElementById("result3_5").style.color = "green";
} else {
document.getElementById("result3_5").innerHTML = "Incorrect. Learn about table tag attributes and try again.";
document.getElementById("result3_5").style.color = "red";
}
}
function checkAnswer1() {
var answer1 = document.getElementById("answer1").value.toLowerCase();
if (answer1 === "ol") {
document.getElementById("result1").innerHTML = "Correct!";
document.getElementById("result1").style.color = "green";
} else {
document.getElementById("result1").innerHTML = "Incorrect. The answer is ol.";
document.getElementById("result1").style.color = "red";
}
}
function checkAnswer2() {
var answer2 = document.getElementById("answer2").value.toLowerCase();
if (answer2 === "ul") {
document.getElementById("result2").innerHTML = "Correct!";
document.getElementById("result2").style.color = "green";
} else {
document.getElementById("result2").innerHTML = "Incorrect. The answer is ul.";
document.getElementById("result2").style.color = "red";
}
}
function checkAnswer3() {
var answer3 = document.getElementById("answer3").value.toLowerCase();
if (answer3 === "table") {
document.getElementById("result3").innerHTML = "Correct!";
document.getElementById("result3").style.color = "green";
} else {
document.getElementById("result3").innerHTML = "Incorrect. The answer is table.";
document.getElementById("result3").style.color = "red";
}
}
function checkAnswer4() {
var answer4 = document.getElementById("answer4").value.toLowerCase();
if (answer4 === "div") {
document.getElementById("result4").innerHTML = "Correct!";
document.getElementById("result4").style.color = "green";
} else {
document.getElementById("result4").innerHTML = "Incorrect. The answer is div.";
document.getElementById("result4").style.color = "red";
}
}
function checkAnswer5() {
var answer5 = document.getElementById("answer5").value.toLowerCase();
if (answer5 === "span") {
document.getElementById("result5").innerHTML = "Correct!";
document.getElementById("result5").style.color = "green";
} else {
document.getElementById("result5").innerHTML = "Incorrect. The answer is span.";
document.getElementById("result5").style.color = "red";
}
}
// Get all the links
var links = document.querySelectorAll(".nav-link");
// Loop through the links
for (var i = 0; i < links.length; i++) {
// Add a click event listener to each link
links[i].addEventListener("click", function(event) {
// event.preventDefault(); // prevent default link behavior
// Remove the "active" class from all links
for (var j = 0; j < links.length; j++) {
links[j].classList.remove("active");
}
// Add the "active" class to the clicked link
this.classList.add("active");
});
}
</script>