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

191
Views
Please explain the reason for this code not working

The code given below should give different output on the basis of the input values but it is not working.

function myFunction() {
  let x = document.getElementById("demo").value;
  let y;
  if (x == "") {
    y = "The field is Empty";
  } else if (isNaN(x)) {
    y = "Input is not a number";
  } else if (x < 5) {
    y = "The number is too low";
  } else(x > 10) {
    y = "The number is too big";
  }
  document.getElementById("p01").innerHTML = y;
}
<input id="demo" type="text">
<button type="button" onclick="myFunction()">Test Input</button>
<p id="p01"></p>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are putting a condition in the else statement: else (x > 10) which can't be done. Change it to else if (x > 10) and you should be good to go.

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!