https://github.com/jasheloper/conditionals-test-3
Test skills with JavaScript conditionals.
https://github.com/jasheloper/conditionals-test-3
conditionals if-else javascript
Last synced: about 1 month ago
JSON representation
Test skills with JavaScript conditionals.
- Host: GitHub
- URL: https://github.com/jasheloper/conditionals-test-3
- Owner: jasheloper
- Created: 2023-10-18T01:46:46.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-24T01:16:23.000Z (over 1 year ago)
- Last Synced: 2023-10-25T01:57:10.847Z (over 1 year ago)
- Topics: conditionals, if-else, javascript
- Language: HTML
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
## Exercise Link
https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Test_your_skills:_Conditionals#conditionals_3
## Instructions
For the final task you are given four variables:
- `machineActive` — contains an indicator of whether the login machine is switched on or not (`true`/`false`).
- `pwd` — Contains the user's login password.
- `machineResult` — begins uninitialized, but is later used to store a response that will be printed to the output panel, letting the user know whether the machine is switched on.
- `pwdResult` — begins uninitialized, but is later used to store a response that will be printed to the output panel, letting the user know whether their login attempt was successful.
We'd like you to create an `if...else` structure that checks whether the machine is switched on and puts a message into the `machineResult` variable telling the user whether it is on or off.
If the machine is on, we also want a second conditional to run that checks whether the `pwd` is equal to `cheese`.
- If so, it should assign a string to `pwdResult` telling the user they logged in successfully.
- If not, it should assign a different string to `pwdResult` telling the user their login attempt was not successful. We'd like you to do this in a single line, using something that isn't an `if...else` structure.
## My Solution
```
let machineActive = true;
let pwd = "cheese";let machineResult;
let pwdResult;// Add your code here
if (machineActive) {
machineResult = "Machine Status = ON";
pwdResult = pwd === "cheese" ? "Login attempt was successful!" : "Login attempt unsuccessful."
} else {
machineResult = "Machine Status = OFF";
}
```