Java Script/JS basic

JS] 99 bottles of beer 퀴즈

CodeMia 2021. 8. 15. 14:50

99 Bottles of Beer 

 

아래와 같은 노래 가사 만들기 

 

99 bottles of beer on the wall, 99 bottles of beer. 

Take one down and pass it around, 98 bottles of beer on the wall. 

 

98 bottles of beer on the wall, 98 bottles of beer.

Take one down and pass it around, 97 bottles of beer on the wall. 

:

:

1 bottle of beer on the wall, 1 bottle of beer.

Take one down and pass it around, no more bottles of beer on the wall. 

 

No more bottles of beer on the wall, no more bottles of beer.

Go to the store and buy some more, 99 bottles of beer on the wall. 

 

 

 


 

내가 한 코딩 

 

 

....

 

 

다른 사람이 한 코딩 

케이스 1

function cheers(){
    var count = 100;
    while(count>2) {
       count--;
       console.log(count + " bottles of beer on the wall, " + count + " bottles of beer. Take one down and pass it around, " + (count-1) + " bottles of beer.");
    }
 
    count[1] = console.log("1 bottle of beer on the wall, 1 bottle of beer. Take one down and pass it around, 1 bottle of beer.");
    count[0] = console.log("No more bottles of beer on the wall, no more bottles of beer. Go to the store and buy some more, 99 bottles of beer. Cheers :-)!");     
}
 
cheers();

 

 

 

 

케이스 2

  1. function song99Bottles(){
  2. var bottles = 99;
  3. while(bottles>0){
  4. console.log(bottles + " bottles of beer on the wall, " + bottles + " bottles of beer. Take one down and pass it around, " + --bottles + " bottles of beer on the wall.");
  5. }

 

--bottles로 따로 빼는 것 없이 문장 안에 들어가서 신선함

1개, 0개 일 때 안되어 있어 아쉬움

 

 

 

케이스 3

  1. var count = 99;
  2. function beer() {
  3. while (count >= 2) {
  4. console.log(count + " bottles of beer on the wall, " + count + " bottles of beer. Take one down pass it around, " + (count-1) + " bottles of beer on the wall.")
  5. count--;
  6. }
  7.  
  8. if (count === 1) {
  9. console.log(count + " bottle of beer on the wall, " + count + " bottle of beer. Take one down pass it around, no bottles of beer on the wall.")
  10. count--;
  11. }
  12. if (count === 0) {
  13. console.log("No more bottles of beer on the wall, no more bottles of beer. Go to the store and buy some more, 99 bottles of beer on the wall.")
  14. }
  15. }
  16.  
  17. beer();

 

내 경우는 0보다 큰 수로 했는데, 이 사람은 2보다 큰 수로 해서 바로 스트링이 나올 수 있게 했음