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

154
Vistas
How to find biggest number using Math object with Prompt and FOR loop or do/while loop?

My goal was to find the biggest number using the Math object in the console. However, How could I use the FOR loop to PROMPT the number 1, number 2 so that I don't have to write the whole object? I just wanted to return the value each time I use for loop but could not think that way so later I had to write an object.


var num = {

x: parseInt(prompt("Enter your number1")),
Y: parseInt(prompt("Enter your number2")),
W: parseInt(prompt("Enter your number1")),
Z: parseInt(prompt("Enter your number1")),

}

console.log(Math.max(num.x, num.Y,num.Z,num.W));

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

0

You can loop over the Object's keys

var num = {
  x: 0,
  Y: 0,
  W: 0,
  Z: 0,
}

Object.keys(num).forEach(key => num[key] = +prompt(`Enter your ${key}`));

// Object.keys(num).forEach(function(key) { 
//   num[key] = +prompt('Enter your ' + key);
// });

console.log(num);

for loop and an array

var nums = [];

for (var i=0; i<4; i++) {
  nums.push(+prompt('Enter your ' + i));
}

console.log(nums);
console.log(Math.max(...nums));

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