Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!