Skip to content

Commit 08500cc

Browse files
Updating starter code for errors and debugging
1 parent e0f20f8 commit 08500cc

11 files changed

+220
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let name = Julie;
2+
console.log("Hello, name);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let day = Wednesday;
2+
console.log(day;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//Run this code first and examine the error message.
2+
//Fix the syntax error then run the code again to check your work.
3+
4+
let launchReady = false;
5+
let fuelLevel = 17000;
6+
7+
if (fuelLevel >= 20000 {
8+
console.log('Fuel level cleared.');
9+
launchReady = true;
10+
} else {
11+
console.log('WARNING: Insufficient fuel!');
12+
launchReady = false;
13+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Run this sample code as-is and examine the output.
2+
// Should the shuttle have launched?
3+
// Did it?
4+
// Do not worry about fixing the code yet, we will do that in the next series of exercises.
5+
6+
let launchReady = false;
7+
let fuelLevel = 17000;
8+
let crewStatus = true;
9+
let computerStatus = 'green';
10+
11+
if (fuelLevel >= 20000) {
12+
console.log('Fuel level cleared.');
13+
launchReady = true;
14+
} else {
15+
console.log('WARNING: Insufficient fuel!');
16+
launchReady = false;
17+
}
18+
19+
if (crewStatus && computerStatus === 'green'){
20+
console.log('Crew & computer cleared.');
21+
launchReady = true;
22+
} else {
23+
console.log('WARNING: Crew or computer not ready!');
24+
launchReady = false;
25+
}
26+
27+
if (launchReady) {
28+
console.log('10, 9, 8, 7, 6, 5, 4, 3, 2, 1...');
29+
console.log('Liftoff!');
30+
} else {
31+
console.log('Launch scrubbed.');
32+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Let’s break the code down into smaller chunks.
2+
// Consider the first if/else block below.
3+
// Add console.log(launchReady) after this block, then run the program.
4+
5+
//Given the fuelLevel value, should launchReady be true or false after the check? Is the program behaving as expected?
6+
7+
let launchReady = false;
8+
let fuelLevel = 17000;
9+
// let crewStatus = true;
10+
// let computerStatus = 'green';
11+
12+
if (fuelLevel >= 20000) {
13+
console.log('Fuel level cleared.');
14+
launchReady = true;
15+
} else {
16+
console.log('WARNING: Insufficient fuel!');
17+
launchReady = false;
18+
}
19+
20+
// if (crewStatus && computerStatus === 'green'){
21+
// console.log('Crew & computer cleared.');
22+
// launchReady = true;
23+
// } else {
24+
// console.log('WARNING: Crew or computer not ready!');
25+
// launchReady = false;
26+
// }
27+
28+
// if (launchReady) {
29+
// console.log('10, 9, 8, 7, 6, 5, 4, 3, 2, 1...');
30+
// console.log('Liftoff!');
31+
// } else {
32+
// console.log('Launch scrubbed.');
33+
// }
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Let’s break the code down into smaller chunks.
2+
// Now consider the second if/else block.
3+
// Add another console.log(launchReady) after this block and run the program.
4+
5+
// Given the values for crewStatus and computerStatus, should launchReady be true or false after the check?
6+
// Is the program behaving as expected?
7+
8+
let launchReady = false;
9+
// let fuelLevel = 17000;
10+
let crewStatus = true;
11+
let computerStatus = 'green';
12+
13+
// if (fuelLevel >= 20000) {
14+
// console.log('Fuel level cleared.');
15+
// launchReady = true;
16+
// } else {
17+
// console.log('WARNING: Insufficient fuel!');
18+
// launchReady = false;
19+
// }
20+
21+
if (crewStatus && computerStatus === 'green'){
22+
console.log('Crew & computer cleared.');
23+
launchReady = true;
24+
} else {
25+
console.log('WARNING: Crew or computer not ready!');
26+
launchReady = false;
27+
}
28+
29+
// if (launchReady) {
30+
// console.log('10, 9, 8, 7, 6, 5, 4, 3, 2, 1...');
31+
// console.log('Liftoff!');
32+
// } else {
33+
// console.log('Launch scrubbed.');
34+
// }
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Now consider both if/else blocks together (keeping the added console.log lines).
2+
// Run the code and examine the output.
3+
4+
// Given the values for fuelLevel, crewStatus and computerStatus, should launchReady be true or false?
5+
// Is the program behaving as expected?
6+
7+
let launchReady = false;
8+
let fuelLevel = 17000;
9+
let crewStatus = true;
10+
let computerStatus = 'green';
11+
12+
if (fuelLevel >= 20000) {
13+
console.log('Fuel level cleared.');
14+
launchReady = true;
15+
} else {
16+
console.log('WARNING: Insufficient fuel!');
17+
launchReady = false;
18+
}
19+
20+
console.log("launchReady = ", launchReady);
21+
22+
if (crewStatus && computerStatus === 'green'){
23+
console.log('Crew & computer cleared.');
24+
launchReady = true;
25+
} else {
26+
console.log('WARNING: Crew or computer not ready!');
27+
launchReady = false;
28+
}
29+
30+
console.log("launchReady = ", launchReady);
31+
32+
// if (launchReady) {
33+
// console.log('10, 9, 8, 7, 6, 5, 4, 3, 2, 1...');
34+
// console.log('Liftoff!');
35+
// } else {
36+
// console.log('Launch scrubbed.');
37+
// }
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// The value of launchReady assigned in the first if/else block gets changed in the second if/else block. Dangerous waters...
2+
// Since the issue is with launchReady, ONE way to fix the logic error is to use a different variable to store the fuel check result.
3+
// Refactor the code to do this. Verify that your change works by updating the console.log statements.
4+
5+
let launchReady = false;
6+
let fuelLevel = 17000;
7+
let crewStatus = true;
8+
let computerStatus = 'green';
9+
10+
if (fuelLevel >= 20000) {
11+
console.log('Fuel level cleared.');
12+
launchReady = true;
13+
} else {
14+
console.log('WARNING: Insufficient fuel!');
15+
launchReady = false;
16+
}
17+
18+
console.log("launchReady = ", launchReady);
19+
20+
if (crewStatus && computerStatus === 'green'){
21+
console.log('Crew & computer cleared.');
22+
launchReady = true;
23+
} else {
24+
console.log('WARNING: Crew or computer not ready!');
25+
launchReady = false;
26+
}
27+
28+
console.log("launchReady = ", launchReady);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//Run this code first and examine the error message.
2+
//Pay close attention to any line numbers mentioned in the message - these will help locate and repair the mistake in the code.
3+
4+
let launchReady = false;
5+
let fuelLevel = 17000;
6+
7+
if (fuellevel >= 20000) {
8+
console.log('Fuel level cleared.');
9+
launchReady = true;
10+
} else {
11+
console.log('WARNING: Insufficient fuel!');
12+
launchReady = false;
13+
}

errors-and-debugging/exercises/DebuggingRuntimeErrors2.js

Whitespace-only changes.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//This block of code hides two syntax errors.
2+
3+
// Run the code and find the mistakes.
4+
// Only ONE error will be flagged at a time.
5+
// Fix that ONE problem, and then re-run the code to check yer work. Avoid trying to fix multiple issues at once.
6+
7+
let launchReady = false;
8+
let crewStatus = true;
9+
let computerStatus = 'green';
10+
11+
if (crewStatus &&& computerStatus === 'green'){
12+
console.log('Crew & computer cleared.');
13+
launchReady = true;
14+
} else {
15+
console.log('WARNING: Crew or computer not ready!');
16+
launchReady = false;
17+
}
18+
19+
if (launchReady) {
20+
console.log(("10, 9, 8, 7, 6, 5, 4, 3, 2, 1...");
21+
console.log("Fed parrot...");
22+
console.log("Ignition...");
23+
console.log("Liftoff!");
24+
} else {
25+
console.log("Launch scrubbed.");
26+
}

0 commit comments

Comments
 (0)