Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

305
Views
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)
    
}

}

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Random returns a decimal number convert it to a integer with:

var c = math.floor(random(1, 4))
about 4 years ago · Juan Pablo Isaza Report

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!