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

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

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 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!