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

165
Views
how to make the statement to repeat itself until it gets true?

I want this statement to repeat itself until the condition is true, forgot the syntax to do so

let gradeAmount = Number(prompt('insert a number between 1 and 5'));
const grades = [];
if (gradeAmount >= 1 && gradeAmount <= 5) {
  for (let i = 0; i < gradeAmount; i++) {
    const grade = Number(prompt('insert the grade'));

    grades.push(grade);
  }
} else {
  alert('invalid number of grades, please insert again');
  gradeAmount = Number(prompt('insert a number between 1 and 5'));
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

A possible solution is to use do...while. This code will keep display alert('invalid number of grades, please insert again') and window.prompt until it meets you condition. Then it will window.prompt for user to enter the number.

const grades = [];
let gradeAmount = Number(prompt('insert a number between 1 and 5'));
do{
if(gradeAmount < 1 || gradeAmount > 5){
alert('invalid number of grades, please insert again');
  gradeAmount = Number(prompt('insert a number between 1 and 5'));
  }
 }
 
 while(gradeAmount < 1 || gradeAmount > 5)
 
 
   for (let i = 0; i < gradeAmount; i++) {
    const grade = Number(prompt('insert the grade'));

    grades.push(grade);
  }
  console.log(grades)

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!