Exercise Solutions: Errors and DebuggingΒΆ

  1. Line 4 needs a closing parenthesis:

    4if (fuelLevel >= 20000) {
    

    Back to the exercises

  1. fuellevel should be fuelLevel on Line 7:

    7if (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:

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

    Back to the exercises