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

369
Vistas
What am I doing wrong in this loop? js

I am trying to solve this loop but I can't solve it

You must create a function called loopDePares that receives a number as a parameter and loops from 0 to 100, displaying each loop number on the console. If the number of the iteration, added to the number passed by parameter, is even, it will show in the console “The number x is even”.

what i did was this

function loopDePartes(numero){
  for (let i = 0; i <numero; i++){
    console.log(i+numero % 2 ? i : "x")
  }
}

loopDePartes(10)
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You had one math error, and one comparison error.

i+numero needs to be wrapped in parens so it take precedence over the modulus operator.

Your ternary was checking the truthiness of the output of that math, instead of checking whether it was even or odd.

Both are corrected below:

function loopDePartes(numero){
  for (let i = 0; i < 100; i++){
    console.log((i+numero) % 2 == 1 
      ? i 
      : `The number ${i+numero} is even`
    )
  }
}

loopDePartes(10)

(Actually, the more I reread your question the less I understand what is the expected output; I think this is what you're looking for but I may have misinterpreted what you meant by "display the loop number", and what "x" is supposed to be in "The number x is even".)

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