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

265
Vistas
How does the var x and var lineY code work?

I have this processing.js code made on khan academy:

background(255, 255, 247);
stroke(173, 222, 237);

for (var i = 0; i < 20; i++) {
    
    var lineY = 20 + (i * 20);
    line(0, lineY, 400, lineY);
    
}

for (var j = 0; j < 20; j++) {
    
    var x = 20 + (j * 20);
    line(x, 0, x, 400);

}

What does the

var lineY = 20 + (i * 20);

code do? And what does the

var x = 20 + (j * 20);

code do?

Im a beginner

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Each one declares (tells javascript to create) a variable (a word), and initializes the value (sets the initial value) to whatever is on the other side of the = sign.

var lineY = 20 + (i * 20);
line(0, lineY, 400, lineY);

is equivalent to

line(0, 20 + (i * 20), 400, 20 + (i * 20));

however, using a variable makes it so you don't have to do the same calculation again (and makes code more readable).

about 4 years ago · Juan Pablo Isaza Denunciar

0

var lineY = 20 + (i * 20);

This means that the variable called lineY will be equal to 20 plus the value of i times 20. So if i is 1, then lineY will equal 40.

The variables i and j will be values of 20 or less, based on the maximum value in the for loop.

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