if else dosn't work
wanna some help in js
This is a login page, there is an option to show or hide password, when I click on the icon I selected it shows the password and work perfectly fine, the issue here when I click back on icon, it doesn't make any action as I ordered, how to fix that?
3 Replies
You need a double or triple equal for comparison. Your if condition is actually assigning and not testing equality.
What is happening in line 8 is input.type gets assigned to be "password" every time but assignments return the value being assigned, so the expression evaluates to the string "password" and a string is only falsy if it's empty, so "password" is truthy and line 10 gets executed. The end result is input.text will always be "text" after the first run.
You should use in if identical operator
if (input.type === "password" )
Thanks brothers I was really stuck!