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?
No description
3 Replies
ChooKing
ChooKing10mo ago
You need a double or triple equal for comparison. Your if condition is actually assigning and not testing equality.
if (input.type === 'password'){}
if (input.type === 'password'){}
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.
ziad_hatem2011
ziad_hatem201110mo ago
You should use in if identical operator if (input.type === "password" )
3moor_m
3moor_m10mo ago
Thanks brothers I was really stuck!