@Harshit_Badolla you are very nearly right here. The main problem is that you have put the line let num = Number(input.value);
in the global scope, so it runs immediately, as soon as the page loads. Given that there is nothing in the input when the page first loads, num
will always be nothing, so you won’t get anything printed when you click the button.
You should put that line inside the click handler so that num
will be equal to the input value when you click the button, not the input value when the page first loads.
Another small tip — if you want it to print all the way up to the num
value, not the number below it, you’ll want to change the for loop exit condition from i < num
to i <= num
.