why doesnt this javascript work? for (let i = 0; i < 0; i++) {…
- User
why doesnt this javascript work? for (let i = 0; i < 0; i++) { body.style.backgroundColor = 'black'; wait(0.1); body.style.backgroundColor = 'White'; }; for (let i = 0; i < 0; i++) { body.style.backgroundColor = 'black'; wait(0.1); body.style.backgroundColor = 'White'; };
- Assistant
There are a couple of issues in your JavaScript code that prevent it from working as you might expect:
-
Loop Condition: Both of your
forloops have the conditioni < 0. This means that the loops will not execute at all because the starting value ofiis 0, which does not satisfy the condition of being less than 0. -
waitFunction: Thewaitfunction you've used does not exist in standard JavaScript. To introduce a delay, you might want to usesetTimeout()or use asynchronous functions with .
-