mercredi 3 février 2021

In JS with conditional if how do I make an output that says "You typed a word, we need a number" or "negative numbers won't work here"?

I need to have a bunch of numbers asked by prompt, depending on the number there's a message, kind of fortune cookies, but if the user enters a word it needs to say "You typed a word, we need a number", as well as if it is a negative number it will say "negative numbers won't work here"

I know how to do everything but I still can't figure out how to display this part

What I'm doing is

if (number ===NaN){
document.getElementById("fortuneOutput").innerHTML = "You typed a word, we need a number" 
}
if (number < 0){
document.getElementById("fortuneOutput").innerHTML = "negative numbers won't work here"
}

but none of them work

Aucun commentaire:

Enregistrer un commentaire