Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0395673

Browse files
authored
Safari does not return an empty string when a prompt is cancelled
title
1 parent 3b25bc5 commit 0395673

File tree

1 file changed

+3
-9
lines changed
  • 1-js/02-first-steps/10-ifelse/4-check-login

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)

AltStyle によって変換されたページ (->オリジナル) /