move around

This commit is contained in:
Ilya Kantor 2019-01-13 20:36:23 +03:00
parent fdad5ff3ac
commit 7e5ffe269e
4 changed files with 1 additions and 3 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 92 KiB

View file

@ -1,25 +0,0 @@
```js run demo
let userName = prompt("Who's there?", '');
if (userName == 'Admin') {
let pass = prompt('Password?', '');
if (pass == 'TheMaster') {
alert( 'Welcome!' );
} else if (pass == '' || pass == null) {
alert( 'Canceled.' );
} else {
alert( 'Wrong password' );
}
} else if (userName == '' || userName == null) {
alert( 'Canceled' );
} else {
alert( "I don't know you" );
}
```
Note the vertical indents inside the `if` blocks. They are technically not required, but make the code more readable.

View file

@ -1,27 +0,0 @@
importance: 3
---
# Check the login
Write the code which asks for a login with `prompt`.
If the visitor enters `"Admin"`, then `prompt` for a password, if the input is an empty line or `key:Esc` -- show "Canceled.", if it's another string -- then show "I don't know you".
The password is checked as follows:
- If it equals "TheMaster", then show "Welcome!",
- Another string -- show "Wrong password",
- For an empty string or cancelled input, show "Canceled."
The schema:
![](ifelse_task.png)
Please use nested `if` blocks. Mind the overall readability of the code.
Hint:
1. passing an empty input to a prompt returns an empty string `''`. Pressing `key:ESC` during a prompt returns `null`.
2. You should use || that we will see in detail on the next chapter. Here some info: in classical programming, the logical OR is meant to manipulate boolean values only. If any of its arguments are true, it returns true, otherwise it returns false.
[demo]