Skip to content

Commit 4a4596f

Browse files
committed
exercise p1
1 parent fa37021 commit 4a4596f

File tree

10 files changed

+77
-10
lines changed

10 files changed

+77
-10
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
// Declare and initialize the variables for exercise 1 here:
22

3+
let engineIndicatorLight = "red blinking";
4+
let spaceSuitsOn = true;
5+
let shuttleCabinReady = true;
6+
let crewStatus = spaceSuitsOn && shuttleCabinReady;
7+
let computerStatusCode = 200;
8+
let shuttleSpeed = 15000;
9+
310
// BEFORE running the code, predict what will be printed to the console by the following statements:
411

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

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,33 @@ let shuttleSpeed = 15000;
99

1010
// a) If crewStatus is true, print "Crew Ready" else print "Crew Not Ready".
1111

12+
if (crewStatus){
13+
console.log("Crew Ready");
14+
} else {
15+
console.log("Crew Not Ready");
16+
}
1217

1318
// 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!"
1419

20+
if (computerStatusCode === 200){
21+
console.log("Please stand by. Computer is rebooting");
22+
} else if (computerStatusCode === 400){
23+
console.log("Success! Computer online");
24+
} else {
25+
console.log("ALERT: Computer offline!");
26+
}
1527

1628
// 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".
1729

30+
if (shuttleSpeed > 17500){
31+
console.log("ALERT: Escape velocity reached!");
32+
} else if (shuttleSpeed < 8000){
33+
console.log("ALERT: Cannot maintain orbit!");
34+
} else {
35+
console.log("Stable speed");
36+
}
1837

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

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

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ let engineTemperature = 1200;
44

55
/* 5) Implement the following checks using if/else if/else statements:
66
7-
a) If fuelLevel is above 20000 AND engineTemperature is at or below 2500, print "Full tank. Engines good."
7+
a) If fuelLevel is above 20000 AND engineTemperature is at or below 2500, print "Full tank. Engines good.""
88
99
b) If fuelLevel is above 10000 AND engineTemperature is at or below 2500, print "Fuel level above 50%. Engines good."
1010
@@ -18,7 +18,36 @@ f) Otherwise, print "Fuel and engine status pending..." */
1818

1919
// Code 5a - 5f here:
2020

21+
if (fuelLevel < 1000 || engineTemperature > 3500 || engineIndicatorLight === "red blinking"){
22+
console.log("ENGINE FAILURE IMMINENT!");
23+
} else if (fuelLevel <= 5000 || engineTemperature > 2500){
24+
console.log("Check fuel level. Engines running hot.");
25+
} else if (fuelLevel > 20000 && engineTemperature <= 2500){
26+
console.log("Full tank. Engines good.");
27+
} else if (fuelLevel > 10000 && engineTemperature <= 2500){
28+
console.log("Fuel level above 50%. Engines good.");
29+
} else if (fuelLevel > 5000 && engineTemperature <= 2500){
30+
console.log("Fuel level above 25%. Engines good.");
31+
} else {
32+
console.log("Fuel and engine status pending...");
33+
}
34+
2135
// 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.
36+
let commandOverride = true;
37+
38+
if (!commandOverride){
39+
if (fuelLevel > 5000 && engineTemperature > 3500 && engineIndicatorLight !== "red blinking") {
40+
console.log("Shuttle ready for launch");
41+
}
42+
} else {
43+
console.log("Shuttle Launch ready");
44+
}
2245

2346
/* 6) b) Code the following if/else check:
2447
If fuelLevel is above 20000 AND engineIndicatorLight is NOT red blinking OR commandOverride is true print "Cleared to launch!" Else print "Launch scrubbed!" */
48+
49+
if (fuelLevel > 20000 && engineIndicatorLight !== "red blinking" || commandOverride === true) {
50+
console.log("Cleared to launch!");
51+
} else {
52+
console.log("Launch scrubbed@"):
53+
}

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ if (fuelLevel >= 20000) {
1717
launchReady = false;
1818
}
1919

20+
console.log(launchReady);
21+
2022
// if (crewStatus && computerStatus === 'green'){
2123
// console.log('Crew & computer cleared.');
2224
// launchReady = true;

errors-and-debugging/exercises/DebuggingLogicErrors3.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ if (crewStatus && computerStatus === 'green'){
2525
console.log('WARNING: Crew or computer not ready!');
2626
launchReady = false;
2727
}
28+
console.log(launchReady);
2829

2930
// if (launchReady) {
3031
// console.log('10, 9, 8, 7, 6, 5, 4, 3, 2, 1...');

errors-and-debugging/exercises/DebuggingLogicErrors5.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Refactor the code to do this. Verify that your change works by updating the console.log statements.
44

55
let launchReady = false;
6+
let crewReady = false;
67
let fuelLevel = 17000;
78
let crewStatus = true;
89
let computerStatus = 'green';
@@ -19,10 +20,17 @@ console.log("launchReady = ", launchReady);
1920

2021
if (crewStatus && computerStatus === 'green'){
2122
console.log('Crew & computer cleared.');
22-
launchReady = true;
23+
crewReady = true;
2324
} else {
2425
console.log('WARNING: Crew or computer not ready!');
25-
launchReady = false;
26+
crewReady = false;
2627
}
2728

28-
console.log("launchReady = ", launchReady);
29+
console.log("crewReady = ", crewReady);
30+
31+
if (!launchReady && crewStatus) {
32+
console.log("10,9,8,7,6,5,4,3,2,1...");
33+
console.log("Liftoff!");
34+
} else {
35+
console.log("Launch scrubbed!");
36+
}

errors-and-debugging/exercises/DebuggingRuntimeErrors1.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/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...");
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'){
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...");
2121
console.log("Fed parrot...");
2222
console.log("Ignition...");
2323
console.log("Liftoff!");

0 commit comments

Comments
 (0)