Skip to content

jasheloper/conditionals-test-3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

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

About

Test skills with JavaScript conditionals.

Topics

Resources

Stars

Watchers

Forks