Jump to content

While loop decrement


Gerardo Castro

Recommended Posts

Gerardo Castro

Boa tarde a todos,

 

Precisava de ajuda com o seguinte exercício, pois estou completamente bloqueado:

"Declare a variable named countdown and assign it the value of 10. In a while loop, decrement the value of countdown once for every iteration and print it. Once countdown hits 0 print 'Blastoff' to the console."

 

Até agora estou aqui:

var countdown = 10;{
    while (countdown > 0) {
        console.log(countdown);
        countdown = countdown - 1;
}
    console.log("Blastoff!");
}

 

 

Output

>>>>Code is incorrect

The first line in your while's block should decrement the value of the variable countdown

10

9

8

7

6

5

4

3

2

1

Blastoff!
Edited by Gerardo Castro
Link to post
Share on other sites

O programa funciona mas o verificador quer exatamente como no enunciado.

O enunciado diz: "decrementar e imprimir".

Deves trocar a ordem das linhas para decrementar aparecer antes que imprimir.

No fim Blastoff não deve ter "!" a não ser que esteja no enunciado.

Edited by Zex
  • Vote 1
Link to post
Share on other sites
Gerardo Castro

Muito muito obrigado, já são muitas horas seguidas nisto e de facto há coisas básicas que escapam.

 

var countdown = 10;
while (countdown > 0){
    countdown--;
    console.log(countdown);
}
console.log("Blastoff");
Citação

 

Output

>>>>Code is correct

9

8

7

6

5

4

3

2

1

0

Blastoff

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.