99 garrafas de suco
Direções:
Escreva um loop que exiba a canção a seguir. Começando em 99 e terminando em 1 garrafa (bottle).
99 bottles of juice on the wall! 99 bottles of juice! Take one down, pass it around... 98 bottles of juice on the wall!
98 bottles of juice on the wall! 98 bottles of juice! Take one down, pass it around... 97 bottles of juice on the wall!
...
2 bottles of juice on the wall! 2 bottles of juice! Take one down, pass it around... 1 bottle of juice on the wall!
1 bottle of juice on the wall! 1 bottle of juice! Take one down, pass it around... 0 bottles of juice on the wall!
Alguns detalhes:
- Observe a pluralização da palavra "bottle" quando você passa de 2 bottles para 1 bottle.
- Seu editor de texto provavelmente tentará corrigir suas reticências
...para o caractere…. Não utilize o caractere de reticências neste quiz.
Código
while ( x > 0){
( x === 2 ) ? console.log ( x + " bottles of juice on the wall! " + x + " bottles of juice! Take one down, pass it around... " + (x - 1) + " bottle es of juice on the wall! ") : (x === 1) ? console.log ( x + " bottle of juice on the wall! " + x + " bottle of juice! Take one down, pass it around... " + (x - 1) + " bottles es of juice on the wall!") : ( x > 2) ?
console.log ( x + " bottles of juice on the wall! " + x + " bottles of juice! Take one down, pass it around... " + (x - 1) + " bottles es of juice on the wall!") : console.log ("end");
x = x - 1;
}
Comentários
Postar um comentário