i want to make a value checker, which would send me my defined response after submitting value.
My requirements:
`If x = 1, x= 2, x=3, then i get response “Not passed”
If x = 4, x=5, x= 6, x= 7, x=8, x=9, x=10 response “passed!”
If x = 4-, x=5+, x=yes response “not a number”
If x= 0, x= 11, x= -2 response “wrong data”
If x is empty (No data entered) response “there are no data!”
`
I am getting stuck when i have to define 4-, 5+,yes as my function is reading those numbers without + and – signs after them and is giving answer “Passed” like for 4 and 5 without + and -, please check it, maybe you get some ideas how to fix it.
For full code: https://codesandbox.io/s/cocky-black-7mezc?file=/ifelse.html:0-2245
My code:
<h2>Ievadi datus</h2>
<span contenteditable="true" ><p id="ievad"></p></span>
<button id="poga1">Check!</button>
<h2>Rezultāts</h2><br>
<span contenteditable="true" ><p id="izv">Vispirms ievadi datus!</p></span>
And Javascript:
var rezultats = "";
document.getElementById("poga1").onclick = function ()
{
let izv = document.getElementById("izv");
let vertejums = document.getElementById("ievad");
let rezultats = parseFloat(vertejums.textContent);
return nep(rezultats);
};
function nep(rezultats){
if (rezultats <= 0 || rezultats > 10.0){
izvads = "Wrong data" ;
}
else if (rezultats < 4.0){
izvads = "Not passed!";
}
else if (rezultats <= 10.0){
izvads = "Passed!" ;
}
else if (rezultats == "4-", "5+", "yes"){
izvads = "It's not a number!" ;
}
else{
izvads = "There are no data!" ;
}
izv = document.getElementById("izv");
izv.innerHTML = izvads;
}
Will be thankful for help!