Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

311
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda