Skip to content

Commit 25e97bb

Browse files
authored
Merge pull request #141 from nhooyr/patch-1
Safari does not return an empty string when a prompt is cancelled
2 parents 5b4bb6a + 0395673 commit 25e97bb

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

1-js/02-first-steps/10-ifelse/4-check-login/solution.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,17 @@ if (userName == 'Admin') {
99

1010
if (pass == 'TheMaster') {
1111
alert( 'Welcome!' );
12-
} else if (pass == null || pass == '') { // (*)
12+
} else if (pass == null) {
1313
alert( 'Canceled.' );
1414
} else {
1515
alert( 'Wrong password' );
1616
}
1717

18-
} else if (userName == null || userName == '') { // (**)
19-
18+
} else if (userName == null) {
2019
alert( 'Canceled' );
21-
2220
} else {
23-
2421
alert( "I don't know you" );
25-
2622
}
2723
```
2824

29-
Please note the `if` check in lines `(*)` and `(**)`. Every browser except Safari returns `null` when the input is canceled, and Safari returns an empty string. So we must treat them same for compatibility.
30-
31-
Also note the vertical indents inside the `if` blocks. They are technically not required, but make the code more readable.
25+
Note the vertical indents inside the `if` blocks. They are technically not required, but make the code more readable.

0 commit comments

Comments
 (0)