Hello, I was doing a simple task on javascript info/ifelse. The tasks section, the 3rd one(show the sign). Although the solution is right there but I tried taking a different approach but it doesn’t work: my codepen work
It only works when I change the strict equality sign from “===” to “==”. Why is that? Can someone pls help me out?
So a few things here, as it sounds like you already know, the strict equality operator (===) checks both the type and the value as to where the equality operator (==) only checks the value even if the types are different.
because you used the window.prompt() method, despite asking the user to input a number, you are actually getting back that number in the form of a string.
Check Window.prompt() for the return value (it’s always a string).
So the way that you could avoid a string being returned is to make sure that you assign it to a number instead by doing:
Number(prompt(‘What Number?’, 1));