Skip to content

Commit 6247ba1

Browse files
committed
Chapter 5
1 parent a81af92 commit 6247ba1

File tree

4 files changed

+74
-8
lines changed

4 files changed

+74
-8
lines changed

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

Lines changed: 21 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") {
@@ -9,3 +14,18 @@ if (engineIndicatorLight === "green") {
914
} else {
1015
console.log("engines are off");
1116
}
17+
// expected output is: engines are off
18+
19+
if (crewStatus && computerStatusCode === 200 && spaceSuitsOn) {
20+
console.log("all systems go");
21+
} else {
22+
console.log("WARNING. Not ready");
23+
}
24+
25+
if (!crewStatus || computerStatusCode !== 200 || !spaceSuitsOn) {
26+
console.log("WARNING. Not ready");
27+
} else {
28+
console.log("all systems go");
29+
}
30+
31+

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

Lines changed: 20 additions & 4 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-
11+
if (crewStatus) {
12+
console.log("Crew Ready");
13+
} else {
14+
console.log("Crew Not Ready");
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) {
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: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
let engineIndicatorLight = 'red blinking';
2-
let fuelLevel = 21000;
3-
let engineTemperature = 1200;
2+
43

54
/* 5) Implement the following checks using if/else if/else statements:
65
@@ -17,8 +16,29 @@ e) If fuelLevel is below 1000 OR engineTemperature is above 3500 OR engineIndica
1716
f) Otherwise, print "Fuel and engine status pending..." */
1817

1918
// Code 5a - 5f here:
20-
19+
let fuelLevel = 20001;
20+
let engineTemperature = 2499;
21+
22+
if (fuelLevel < 1000 || engineTemperature > 3500 || engineIndicatorLight === "red blinking"){
23+
console.log("ENGINE FAILURE IMMINENT!");
24+
} else if (fuelLevel <= 5000 || engineTemperature > 2500) {
25+
console.log("Check fuel level. Engines running hot.");
26+
} else if (fuelLevel > 20000 && engineTemperature <= 2500) {
27+
console.log("Full tank. Engines good.");
28+
} else if (fuelLevel > 10000 && engineTemperature <= 2500) {
29+
console.log("Fuel level above 50%. Engines good.");
30+
} else if (fuelLevel > 5000 && engineTemperature <= 2500) {
31+
console.log("Fuel level above 25%. Engines good.");
32+
} else {
33+
console.log("Fuel and engine status pending...");
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.
2236

2337
/* 6) b) Code the following if/else check:
2438
If fuelLevel is above 20000 AND engineIndicatorLight is NOT red blinking OR commandOverride is true print "Cleared to launch!" Else print "Launch scrubbed!" */
39+
let commandOverride = true;
40+
if (fuelLevel > 20000 && engineIndicatorLight !== "red blinking" || commandOverride === true) {
41+
console.log("Cleared to launch!");
42+
} else {
43+
console.log("Launch scrubbed!");
44+
}

data-and-variables/exercises/data-and-variables-exercises.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,13 @@ let daysToTheMoon = hoursToTheMoon / 24;
3333

3434
// Print the results of the trip to the moon below
3535
console.log(nameOfSpaceShuttle + " will take " + daysToTheMoon + " days to reach the moon. ");
36+
console.log("Hello");
37+
let name = "Miranda";
38+
let age = 28;
39+
let favoriteFruit = "blueberries";
40+
const input = require('readline-sync');
41+
let answer = input.question("Hey there buddy ol pal how's the weather today?");
42+
//string interpolation example below
43+
console.log(`Wow! So the weather is ${answer} today? Neat!`);
44+
//cocatenation example below
45+
console.log("Wow! So the weather is " + answer + "today? Neat!");

0 commit comments

Comments
 (0)