Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Random variable controlling color isn't changing every time the for loop happens

my code is working creating a line diagonally forward and down but the light color never changes, it always just stays red. Can anyone help me fix this? BTW the red part is from earlier in the code meaning that none of the if statements are working in the loop
the code controls the lights on the right side of the house

function lightsDown(x,y,ln,s) {

for (u = 0; u < ln; u++) {
    
    var c = random(1,4)
    
    if (c === 1) {
        
        fill('green')
        
    } 
    if (c === 2) {
        fill ('red')
    }
    if (c === 3) {
        fill('yellow')
    }
    if (c === 4) {
        fill('blue')
    }
        
    circle((x+4.5*s)-(2.67*s/ln)*u,y-(2.67*s/ln*u), s/4)
    
}

}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You’re condition on the if statement seems wrong. It should be (c === 1). And converting the variable c to int.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading