How do I replace the "NaN" value with "error" or something like it? (For ecample when ypu press valculate without parameter) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How do I replace the "NaN" value with "error" or something like it? (For ecample when ypu press valculate without parameter)

https://code.sololearn.com/WTFyM95eGJw6/?ref=app

24th Jul 2020, 7:40 PM
Stefan
Stefan - avatar
2 Answers
+ 2
if (isNaN(calculate)) {calculate = "Err"} document.querySelector("#result").innerHTML = calculate;
24th Jul 2020, 8:12 PM
Russ
Russ - avatar
0
You should first change the input type from text to number: type="number" And then just add an error handling in your code, you can check with JS, if either the input or your result is a number and print something different if not.
24th Jul 2020, 8:05 PM
Sandra Meyer
Sandra Meyer - avatar