Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

309
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda