Exercise Solutions: Errors and DebuggingΒΆ

  1. Line 4 needs a closing parenthesis:

    4
    if (fuelLevel >= 20000) {
    

    Back to the exercises

  1. fuellevel should be fuelLevel on Line 7:

    7
    if (fuelLevel >= 20000) {
    

    Back to the exercises

  1. Check your logic

    1. Should the shuttle have launched? Did it?

      The shuttle should not have launched. However, the messages to the console tell a different story. Without any changes, the original code outputs:

      WARNING: Insufficient fuel!
      Crew & computer cleared.
      10, 9, 8, 7, 6, 5, 4, 3, 2, 1...
      Liftoff!
      
    1. Given crewStatus and computerStatus, should launchReady be true or false after this check?

      With their initial values set to true and 'green', line 14 evaluates to true and launchReady is set to true. If it's value on dependent on the value of these variables only (crewStatus and computerStatus), then launchReady should be true after this check.

    1. Repair the launch readiness checks:

       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      let launchReady = false;
      let crewReady = false;
      let fuelLevel = 17000;
      let crewStatus = true;
      let computerStatus = 'green';
      
      if (fuelLevel >= 20000) {
         console.log('Fuel level cleared.');
         launchReady = true;
      } else {
         console.log('WARNING: Insufficient fuel!');
         launchReady = false;
      }
      console.log("launchReady = ", launchReady);
      
      if (crewStatus && computerStatus === 'green'){
         console.log('Crew & computer cleared.');
         crewReady = true;
      } else {
         console.log('WARNING: Crew or computer not ready!');
         crewReady = false;
      }
      console.log("crewReady = ", crewReady);
      

    Back to the exercises