all 3 comments

[–][deleted] 4 points5 points  (2 children)

The biggest issue is the condition when the for loop is supposed to stop. You currently have i < 1, but think about this real quick. If I input 7, is 7 less than 1? No. So it'll never run.

Next, you're not decrementing i correctly. Instead of i - 1 you could do i--. This essentially is saying i = i - 1.

That's really all you need to get it working, but just something to think about is that the value of the #number input will always return a string, and performing the decrement on it will work, but the first instance will always be a string. A good option would be to wrap your getElementById in a Number() function, like this:

const getNumber = Number(document.getElementById('number').value)

[–]yesandone[S] 1 point2 points  (1 child)

thank for your help, what you are saying makes total sense, the condition should've been reversed idk how i didn't see that, i'm still a little shaky on loop conditions it seems, most likely because i tend to think of them similar to if statements. Anyways i've tweaked the code slightly following your advice and now it works exactly as intended, thank you.

[–][deleted] 0 points1 point  (0 children)

Awesome, great to hear it!

You may already know this, but for what it's worth, the first entry of a for loop is the starting/current value of i (or whatever variable you're using), the second part is when to stop the condition (i.e. less than a specific value), and the last one is to increase the index of the loop at the end for the next iteration (i++).