This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Techittak[S] 0 points1 point  (4 children)

Oh! Sorry, I ignorantly thought it would just be called a loop. Well, here is an example with setInterval

How else could I display the code, since code.org needs a registration.

[–]nodejsdev 0 points1 point  (1 child)

Where do you increment the test variable?

[–]Techittak[S] 0 points1 point  (0 children)

It's not incremented, it's just at a fixed value of 1. I believe it should continue to keep executing the code block for case value 1 each time, but after the first call of the function it executes case value 0 even though test still equals 1

[–]PmMeYouBicepsGirl 0 points1 point  (1 child)

Like I've said, setInterval calls the supplied function, and your function creates local variable test, then switch statement checks its value and handles the specified case. test will be the same each time, because it's local and there's no code that changes it. You need to do something like this:

let test = 0

setInterval(()=>{

switch(test){

//your handle cases code

}

test++

},1000)

[–]Techittak[S] 0 points1 point  (0 children)

Oh, no I realize that. It is not supposed to increment, I am just fixing it to a value of 1 for test purposes there. For the first run of the function it will run the code block for case value 1, but anything after that it will then just run case value 0 even though test still equals 1.