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

246
Vistas
Why doesn't my JavaScript program to find odd numbers work?

I made a simple js code to input start value and end value form prompt and then find all the odd numbers, unfortunately it's not working properly. when i input 1 and 10 it'll work, but when i input 5 for sValue(start value) the program won't work. any idea?

    var odd = [];
    var sValue = prompt("start");
    var eValue = prompt("end");

    for (var i = sValue; i <= eValue; i++) {

        if (i % 2 != 0) {
            odd.push(i);
        }
    }

    alert(odd);

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

0

Because the value of prompt is a string. You need to convert it to a number with parseInt(v, 10).

var odd = [];
var sValue = parseInt(prompt("start"), 10);
var eValue = parseInt(prompt("end"), 10);

for (var i = sValue; i <= eValue; i++) {

  if (i % 2 != 0) {
    odd.push(i);
  }
}

alert(odd);

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