Exercise Solutions: Booleans and ConditionalsΒΆ

  1. Declare and initialize the following variables for our space shuttle.

    1let engineIndicatorLight = "red blinking";
    2let spaceSuitsOn = true;
    3let shuttleCabinReady = true;
    4let crewStatus = spaceSuitsOn && shuttleCabinReady;
    5let computerStatusCode = 200;
    6let shuttleSpeed = 15000;
    

    Back to the exercises

  1. Write conditional expressions to satisfy the safety rules.

    1. 1if (crewStatus) {
      2   console.log("Crew Ready");
      3} else {
      4   console.log("Crew Not Ready");
      5}
      
    2. 1if (computerStatusCode === 200) {
      2   console.log("Please stand by. Computer is rebooting.");
      3} else if (computerStatusCode === 400) {
      4   console.log("Success! Computer online.");
      5} else {
      6   console.log("ALERT: Computer offline!");
      7}
      
    3. 1if (shuttleSpeed > 17500) {
      2   console.log("ALERT: Escape velocity reached!");
      3} else if (shuttleSpeed < 8000) {
      4   console.log("ALERT: Cannot maintain orbit!");
      5} else {
      6   console.log("Stable speed.");
      7}
      

    Back to the exercises

  1. Monitor the shuttle's fuel status.

     1if (fuelLevel < 1000 || engineTemperature > 3500 || engineIndicatorLight === "red blinking") {
     2   console.log("ENGINE FAILURE IMMINENT!");
     3} else if (fuelLevel <= 5000 || engineTemperature > 2500) {
     4   console.log("Check fuel level. Engines running hot.");
     5} else if (fuelLevel > 20000 && engineTemperature <= 2500) {
     6   console.log("Full tank. Engines good.");
     7} else if (fuelLevel > 10000 && engineTemperature <= 2500) {
     8   console.log("Fuel level above 50%. Engines good.");
     9} else if (fuelLevel > 5000 && engineTemperature <= 2500) {
    10   console.log("Fuel level above 25%. Engines good.");
    11} else {
    12   console.log("Fuel and engine status pending...");
    13}
    

    Back to the exercises