-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwhile.html
More file actions
42 lines (35 loc) · 981 Bytes
/
while.html
File metadata and controls
42 lines (35 loc) · 981 Bytes
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
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<p id="lyrics"><p>
<script>
// var n = 100
// var song = ''
// while ( n >= 0 ) {
// if ( n !== 0 ) {
// song = song + ' ' + n + " bottles of beer on the wall! chug, chug, chug"
// } else {
// song+= " no bottles of beer! stumble, stumble, stumble..."
// }
// n--
// }
// document.querySelector('#lyrics').textContent = song;
var n = 100
var song = '<ul class=lyrics>'
while ( n >= 0 ) {
if ( n !== 0 ) {
song = song + '<li>' + n + " bottle" + (n === 1 ? '' : 's')
+ " of beer on the wall! chug, chug, chug</li>"
} else {
song+= "<li>no bottles of beer! stumble, stumble, stumble...</li>"
}
n--
}
song += "</ul>"
document.querySelector('#lyrics').innerHTML = song
</script>
</body>
</html>