Practice Exercises #28

Hi there,

I wanted to just check if the solutions for these exercises are not working not only for me, but if you maybe are encountering the same issue.

When i am copying the a) part of the code, everything is ok.

When i copy and paste the solution code for the b) part, I get the following error in the console:
Uncaught SyntaxError: Identifier ‘num’ has already been declared

Are you facing the same issue?

Thanks,
Peter

Probably you are copy/paste the 2 results at the same time, Part A of the solution is just to get the inputed number into a while loop, second part you can add it but the num variable should be renamed to something else, because your syntax errors mean that you are declaring the same variable twice (let num & var num).

Carlos Z.

Thank you for your reply.

I renamed the num variable given in the b) and the code is working now. I am not quite sure if the code is working properly, though.

For refference i am gonna paste the instructions:

"a) Create a program that takes a number as input from the user, and prints all
numbers from 0 up to this number (hint: while …).
b) Expand the program with a new while loop that requests input from the user for
each “round”. When the user enters the number 10, the program must end. "

The given code in the solution executes as following: a window pops up requesting a number. First time, when you enter any given number, it prints out in the console all numbers from 0 up to the chosen number. If you havent chosen number 10 the browser asks you again for a number with a pop-up. When you enter the second number(different than 10), the browser again asks you for another number via pop-up (and doesnt print the numbers from 0 to chosen number to the console)//this is where i understand there is a mistake - as i am understanding the instructions, the program should repeat each round, so each time a user enters a number different from 10 the program should print all numbers from 0 up to the chosen number - meaning each round it should print numbers from 0 to chosen number(if it is different than 10). The code given in the solution prints the numbers from 0 up to the chosen number only first time.

Best,
Peter