forked from sf-wdi-30/problem-set-js-basics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bottles-of-beer-song.js
48 lines (41 loc) · 1.17 KB
/
bottles-of-beer-song.js
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
/*
Create the "Bottles of beer on the wall" song (watch out for infinite loops!):
```
5 bottles of beer on the wall,
5 bottles of beer!
Take one down and pass it around,
4 bottles of beer on the wall...
4 bottles of beer on the wall,
4 bottles of beer!
Take one down and pass it around,
3 bottles of beer on the wall...
etc.
```
Bonuses
- How would you change "0" to "No more"?
- How would you fix "1 bottles of beer"?
*/
// YOUR CODE HERE
function writeSong(a) {
for (var i = a; i > 0; i--){
if (i===1){
console.log (i + " bottle of beer on the wall")
console.log (i + " bottle of beer!")
console.log ("Take one down and pass it around,")
}
else {
console.log (i + " bottles of beer on the wall,")
console.log (i + " bottles of beer!")
console.log ("Take one down and pass it around,")
}
if (i === 1){
console.log ("No more bottles of beer on the wall...")
} else if (i === 2){
console.log (i-1 + " bottle of beer on the wall...")
} else {
console.log (i-1 + " bottles of beer on the wall...")
}
console.log("")
}
}
writeSong(5);