Skip to content

Commit 337d2bb

Browse files
committed
V1 HW CH6
1 parent da7c60a commit 337d2bb

9 files changed

+57
-20
lines changed

errors-and-debugging/exercises/Debugging1stSyntaxError.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
let launchReady = false;
55
let fuelLevel = 17000;
66

7-
if (fuelLevel >= 20000 {
7+
if (fuelLevel >= 20000) {//MISSING CLOSING PARENTHESIS
88
console.log('Fuel level cleared.');
99
launchReady = true;
1010
} else {

errors-and-debugging/exercises/DebuggingLogicErrors1.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,28 @@ if (launchReady) {
2929
console.log('Liftoff!');
3030
} else {
3131
console.log('Launch scrubbed.');
32-
}
32+
}
33+
34+
//program runs no errors shown when running node DebuggingLogicErrors1.js
35+
//fuel lvl is lss than 20000 and launch ready is false
36+
//expected output 'launch scrubbed'
37+
//current output:
38+
/*Fuel level cleared.
39+
10, 9, 8...
40+
Fed parrot...
41+
6, 5, 4...
42+
Ignition...
43+
3, 2, 1...
44+
Liftoff!
45+
*/
46+
47+
/* SOLUTION FROM TEXTBOOK TO COMPARE TO MY RESULTS
48+
The shuttle should not have launched. However, the messages to the console tell a different story. Without any changes, the original code outputs:
49+
50+
```console
51+
WARNING: Insufficient fuel!
52+
Crew & computer cleared.
53+
10, 9, 8, 7, 6, 5, 4, 3, 2, 1...
54+
Liftoff!
55+
```
56+
*/

errors-and-debugging/exercises/DebuggingLogicErrors2.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Add console.log(launchReady) after this block, then run the program.
44

55
//Given the fuelLevel value, should launchReady be true or false after the check? Is the program behaving as expected?
6+
//FALSE + THE PROGRAM IS NOT RUNNING AS EXPECTED
67

78
let launchReady = false;
89
let fuelLevel = 17000;
@@ -15,7 +16,8 @@ if (fuelLevel >= 20000) {
1516
} else {
1617
console.log('WARNING: Insufficient fuel!');
1718
launchReady = false;
18-
}
19+
}
20+
console.log(launchReady);
1921

2022
// if (crewStatus && computerStatus === 'green'){
2123
// console.log('Crew & computer cleared.');
@@ -30,4 +32,5 @@ if (fuelLevel >= 20000) {
3032
// console.log('Liftoff!');
3133
// } else {
3234
// console.log('Launch scrubbed.');
33-
// }
35+
// }
36+

errors-and-debugging/exercises/DebuggingLogicErrors3.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
// Given the values for crewStatus and computerStatus, should launchReady be true or false after the check?
66
// Is the program behaving as expected?
7+
//CREWSTATUS & COMPUTERSTATUS ARE TRUE BUT THE OUTPUT IS NOT EXPECTED BECAUSE LAUNCHREADY IS STILL FALSE
78

89
let launchReady = false;
910
// let fuelLevel = 17000;
@@ -25,10 +26,11 @@ if (crewStatus && computerStatus === 'green'){
2526
console.log('WARNING: Crew or computer not ready!');
2627
launchReady = false;
2728
}
28-
29+
console.log(launchReady);
2930
// if (launchReady) {
3031
// console.log('10, 9, 8, 7, 6, 5, 4, 3, 2, 1...');
3132
// console.log('Liftoff!');
3233
// } else {
3334
// console.log('Launch scrubbed.');
34-
// }
35+
// }
36+

errors-and-debugging/exercises/DebuggingLogicErrors4.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
// Given the values for fuelLevel, crewStatus and computerStatus, should launchReady be true or false?
55
// Is the program behaving as expected?
6+
//IF PROGRAM IS ONLY DEPENDANT ON CREWSTATUS AND COMPUTER STATUS LAUNCH OUTPUT WOULD BE EXPECTED RESULT BUT FUELLEVEL IS FALSE AND EXPECTED OUTPUT IS NOT CORRECT.
67

78
let launchReady = false;
89
let fuelLevel = 17000;
@@ -34,4 +35,5 @@ console.log("launchReady = ", launchReady);
3435
// console.log('Liftoff!');
3536
// } else {
3637
// console.log('Launch scrubbed.');
37-
// }
38+
// }
39+

errors-and-debugging/exercises/DebuggingLogicErrors5.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,31 @@
22
// 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.
33
// Refactor the code to do this. Verify that your change works by updating the console.log statements.
44

5-
let launchReady = false;
5+
let launchReady = false;//dont change
66
let fuelLevel = 17000;
77
let crewStatus = true;
88
let computerStatus = 'green';
99

10-
if (fuelLevel >= 20000) {
10+
if (launchReady === true && fuelLevel >= 20000) {
1111
console.log('Fuel level cleared.');
12-
launchReady = true;
12+
1313
} else {
1414
console.log('WARNING: Insufficient fuel!');
15-
launchReady = false;
1615
}
1716

1817
console.log("launchReady = ", launchReady);
1918

20-
if (crewStatus && computerStatus === 'green'){
19+
if (launchReady === true && crewStatus && computerStatus === 'green'){
2120
console.log('Crew & computer cleared.');
22-
launchReady = true;
2321
} else {
2422
console.log('WARNING: Crew or computer not ready!');
25-
launchReady = false;
2623
}
2724

28-
console.log("launchReady = ", launchReady);
25+
console.log("launchReady = ", launchReady);
26+
27+
if (launchReady === true && crewStatus && computerStatus === 'green') {
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+
}

errors-and-debugging/exercises/DebuggingRuntimeErrors1.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
let launchReady = false;
55
let fuelLevel = 17000;
66

7-
if (fuellevel >= 20000) {
7+
if (fuelLevel >= 20000) {//lowercase instead of camel case?
88
console.log('Fuel level cleared.');
99
launchReady = true;
1010
} else {
1111
console.log('WARNING: Insufficient fuel!');
1212
launchReady = false;
13-
}
13+
}
14+
15+
//fuel level is not defined

errors-and-debugging/exercises/DebuggingRuntimeErrors2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if (launchReady) {
1414
console.log("Fed parrot...");
1515
console.log("6, 5, 4...");
1616
console.log("Ignition...");
17-
consoul.log("3, 2, 1...");
17+
console.log("3, 2, 1...");//CONSOUL!??
1818
console.log("Liftoff!");
1919
} else {
2020
console.log("Launch scrubbed.");

errors-and-debugging/exercises/DebuggingSyntaxErrors2.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ let launchReady = false;
88
let crewStatus = true;
99
let computerStatus = 'green';
1010

11-
if (crewStatus &&& computerStatus === 'green'){
11+
if (crewStatus && computerStatus === 'green'){// 3 & SIGNS??
1212
console.log('Crew & computer cleared.');
1313
launchReady = true;
1414
} else {
@@ -17,7 +17,7 @@ if (crewStatus &&& computerStatus === 'green'){
1717
}
1818

1919
if (launchReady) {
20-
console.log(("10, 9, 8, 7, 6, 5, 4, 3, 2, 1...");
20+
console.log(("10, 9, 8, 7, 6, 5, 4, 3, 2, 1..."));//MISSING ENDING PARENTHESIS
2121
console.log("Fed parrot...");
2222
console.log("Ignition...");
2323
console.log("Liftoff!");

0 commit comments

Comments
 (0)