An open API service indexing awesome lists of open source software.

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.

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";
}
```