Skip to content
Advertisement

I tried to make a Color Flipper in JS without tutorials and it doesn’t work

It looks logically fine(to me), but I have no idea why it doesn’t work. If someone can explain to me the logic behind why it doesn’t work I would be forever grateful.

JavaScript
JavaScript

The way I think it works(and I’m totally wrong probably) is that the i value iterates through the array of colours until it hits 9 and then the if statement changes it back to 0. But it does not work like that apparently… XD

Advertisement

Answer

You just need to update the if condition. Also, place your if condition at the start of the button click function.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement