Skip to content

Commit a393513

Browse files
committed
Worked on Debugging exercises
1 parent 18f96f7 commit a393513

File tree

7 files changed

+39
-10
lines changed

7 files changed

+39
-10
lines changed

booleans-and-conditionals/exercises/part-1.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
// Declare and initialize the variables for exercise 1 here:
2-
2+
let engineIndicatorLight = "red blinking";
3+
let spaceSuitsOn = true;
4+
let shuttleCabinReady = true;
5+
let crewStatus = spaceSuitsOn && shuttleCabinReady;
6+
let computerStatusCode = 200;
7+
let shuttleSpeed = 15000;
38
// BEFORE running the code, predict what will be printed to the console by the following statements:
49

510
if (engineIndicatorLight === "green") {

booleans-and-conditionals/exercises/part-2.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,30 @@ let shuttleSpeed = 15000;
88
// 3) Write conditional expressions to satisfy the following safety rules:
99

1010
// a) If crewStatus is true, print "Crew Ready" else print "Crew Not Ready".
11+
if(crewStatus === true){
12+
console.log("Crew Ready");
13+
} else {console.log("Crew Not Ready");
1114

15+
}
1216

1317
// b) If computerStatusCode is 200, print "Please stand by. Computer is rebooting." Else if computerStatusCode is 400, print "Success! Computer online." Else print "ALERT: Computer offline!"
14-
18+
if (computerStatusCode === 200){
19+
console.log("Please stand by. Computer is rebooting.");
20+
} else if (computerStatusCode === 400){
21+
console.log("Success! Computer online.");
22+
} else{
23+
console.log("ALERT: Computer offline!");
24+
}
1525

1626
// c) If shuttleSpeed is > 17,500, print "ALERT: Escape velocity reached!" Else if shuttleSpeed is < 8000, print "ALERT: Cannot maintain orbit!" Else print "Stable speed".
17-
27+
if(shuttleSpeed > 17500){
28+
console.log("ALERT: Escape velocity reached!");
29+
} else if( shuttleSpeed < 8000){
30+
console.log("ALERT: Cannot maintain orbit!");
31+
} else{
32+
console.log("Stable speed");
33+
}
1834

1935
// 4) PREDICT: Do the code blocks shown in the 'predict.txt' file produce the same result?
2036

21-
console.log(/* "Yes" or "No" */);
37+
console.log("Yes");

booleans-and-conditionals/exercises/part-3.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@ e) If fuelLevel is below 1000 OR engineTemperature is above 3500 OR engineIndica
1717
f) Otherwise, print "Fuel and engine status pending..." */
1818

1919
// Code 5a - 5f here:
20-
20+
if(fuelLevel >20000 && engineTemperature < 2500){
21+
console.log("Full tank. Engines good.");
22+
} else if(fuelLevel >10000 && engineTemperature <= 2500){
23+
console.log("Fuel level above 50%. Engines good.");
24+
} else if(fuelLevel > 5000 && engineTemperature <=2500){
25+
console.log("Fuel level above 25%. Engines good.");
26+
}else if(fuelLevel <=5000 || engineTemperature >2500){
27+
console.log("Check fuel level. Engines running hot.");
28+
} else if(fuelLevel < 1000 || engineTemperature >3500 || engineIndicatorLight)
2129
// 6) a) Create the variable commandOverride, and set it to be true or false. If commandOverride is false, then the shuttle should only launch if the fuel and engine check are OK. If commandOverride is true, then the shuttle will launch regardless of the fuel and engine status.
2230

2331
/* 6) b) Code the following if/else check:

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) {
88
console.log('Fuel level cleared.');
99
launchReady = true;
1010
} else {

errors-and-debugging/exercises/DebuggingLogicErrors2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if (fuelLevel >= 20000) {
1616
console.log('WARNING: Insufficient fuel!');
1717
launchReady = false;
1818
}
19-
19+
//It should be false
2020
// if (crewStatus && computerStatus === 'green'){
2121
// console.log('Crew & computer cleared.');
2222
// launchReady = true;

errors-and-debugging/exercises/DebuggingLogicErrors3.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Let’s break the code down into smaller chunks.
1+
``// Let’s break the code down into smaller chunks.
22
// Now consider the second if/else block.
33
// Add another console.log(launchReady) after this block and run the program.
44

@@ -25,7 +25,7 @@ if (crewStatus && computerStatus === 'green'){
2525
console.log('WARNING: Crew or computer not ready!');
2626
launchReady = false;
2727
}
28-
28+
//It should be true
2929
// if (launchReady) {
3030
// console.log('10, 9, 8, 7, 6, 5, 4, 3, 2, 1...');
3131
// console.log('Liftoff!');

errors-and-debugging/exercises/DebuggingLogicErrors4.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if (crewStatus && computerStatus === 'green'){
2626
console.log('WARNING: Crew or computer not ready!');
2727
launchReady = false;
2828
}
29-
29+
//No matter what the fuel was doing it would set launch ready if the crew and computer were correct
3030
console.log("launchReady = ", launchReady);
3131

3232
// if (launchReady) {

0 commit comments

Comments
 (0)