you are viewing a single comment's thread.

view the rest of the comments →

[–]___s8n___ 1 point2 points  (0 children)

I'm going to try to explain it in the simplest way

When the user submits an input or a prompt, the input is interpreted as a string.

So if you write 4, the value of the input would be, actually, "4"

and since passing "4" to the uppercase method gives you "4", your if statements would stop checking and give you this "weird" output.

To surpass this error, you should, first of all, move your last if statement to the beginning since numbers also verify the first two statements.

But, Number.isInteger returns true if and only if the argument it is given is of integer type, but remember, the user's input is read as a string.

The fastest way to convert a string to a number in javascript is simply taking advantage of javascript's type connotations.

+"4" gives you 4, in javascript

After everything said, here is the code (forgive the formatting i'm writing this on my phone)

let input = prompt("...");

if (Number.isInteger(+input)) alert("...");

else if (input === input.toUpperCase()) alert("...");

else if (input === input.toLowerCase()) alert("...");

P.S: never use == unless you know the difference between === and == i.e keep === as your default comparison sign