Skip to content

Commit 31631df

Browse files
committed
completed week 2 exercises
1 parent 1b2d229 commit 31631df

File tree

8 files changed

+116
-52
lines changed

8 files changed

+116
-52
lines changed

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

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
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
8+
let fuelLevel = true;
9+
let commandOverride = true || false
310
// BEFORE running the code, predict what will be printed to the console by the following statements:
411

512
if (engineIndicatorLight === "green") {
@@ -9,3 +16,42 @@ if (engineIndicatorLight === "green") {
916
} else {
1017
console.log("engines are off");
1118
}
19+
20+
if (crewStatus) {
21+
console.log ("Crew Ready");
22+
} else {
23+
console.log ("Crew Not Ready");
24+
}
25+
26+
if (computerStatusCode === 200) {
27+
console.log ("Please stand by. Computer is rebooting.");
28+
} else if (computerStatusCode === 400) {
29+
console.log ("Success! Computer online!");
30+
} else {
31+
console.log ("ALERT: Computer offline!");
32+
}
33+
34+
if (shuttleSpeed > 17500) {
35+
console.log ("ALERT: Escape velocity reached!");
36+
} else if (shuttleSpeed < 8000) {
37+
console.log ("ALERT: Cannot maintain orbit!");
38+
} else {
39+
console.log ("Stable speed");
40+
}
41+
42+
if (fuelLevel < 1000 || engineTemperature > 3500 || engineIndicatorLight === "red blinking"){
43+
console.log("ENGINE FAILURE IMMINENT!");
44+
} else if (fuelLevel <= 5000 || engineTemperature > 2500){
45+
console.log("Check fuel level. Engines running hot.");
46+
} else if (fuelLevel > 20000 && engineTemperature <= 2500){
47+
console.log("Full tank. Engines good.");
48+
} else if (fuelLevel > 10000 && engineTemperature <= 2500){
49+
console.log("Fuel level above 50%. Engines good.");
50+
} else if (fuelLevel > 5000 && engineTemperature <= 2500){
51+
console.log("Fuel level above 25%. Engines good.");
52+
} else {
53+
console.log("Fuel and engine status pending...");
54+
}
55+
// I'm stuck here.
56+
57+
if (fuelLevel > 20000 && !engineIndicatorLight)

booleans-and-conditionals/studio/data-variables-conditionals.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,46 @@
11
// Initialize Variables below
2-
2+
let date = ("Monday 2019-03-18");
3+
let time = ("10:05:34");
4+
let astronautCount = (7);
5+
let astronautStatus = ("Ready");
6+
let averageAstronautMassKg = (80.7);
7+
let crewMassKg = astronautCount * averageAstronautMassKg;
8+
let fuelMassKg = (760000);
9+
let shuttleMassKg = (74842.31);
10+
let totalMassKg = crewMassKg + fuelMassKg + shuttleMassKg;
11+
let maximumMassLimit = (850000);
12+
let fuelTempCelsius = (-225);
13+
let minimumFuelTemp = (-300);
14+
let maximumFuelTemp = (-150);
15+
let fuelLevel = (100);
16+
let weatherStatus = ("Clear");
17+
let preparedForLiftOff = (false);
318
// add logic below to verify total number of astronauts for shuttle launch does not exceed 7
19+
if (astronautCount<=7){
20+
if (astronautStatus==="Ready"); {
21+
22+
23+
if (totalMassKg < maximumMassLimit){
24+
if ((fuelTempCelsius === minimumFuelTemp) || (fuelTempCelsius <= maximumFuelTemp)){
25+
if (fuelLevel === 100){
26+
if (weatherStatus === "clear"){
27+
preparedForLiftOff = true;
28+
if (preparedForLiftOff === true){
29+
console.log("--------")
30+
}
31+
32+
}
33+
}
34+
}
35+
}
36+
}
37+
}
38+
if (preparedForLiftOff === true){
39+
console.log(----------"")
40+
console.log("Date:" +date)
441

42+
}
43+
544
// add logic below to verify all astronauts are ready
645

746
// add logic below to verify the total mass does not exceed the maximum limit of 850000
Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,7 @@
1-
// Declare and assign the variables below
2-
let shuttleName = "Determination";
3-
let speed = 17500;
4-
let kmToMars = 225000000;
5-
let kmToMoon = 384400;
6-
let milesPerKm = 0.621
1+
let num = 7;
72

8-
// Use console.log to print the 'typeof' each variable. Print one item per line.
9-
console.log(typeof "Determination");
10-
console.log(typeof 17500);
11-
console.log(typeof 225000000);
12-
console.log(typeof 384400);
13-
console.log(typeof 0.621);
14-
// Calculate a space mission below
15-
let milesToMars = kmToMars * milesPerKm;
16-
let hoursToMars = milesToMars / speed;
17-
let daysToMars = hoursToMars / 24;
18-
// Print the results of the space mission calculations below
19-
console.log(shuttleName + " will take " + daysToMars + " days to reach Mars.");
20-
// Calculate a trip to the moon below
21-
let milesToMoon = kmToMoon * milesPerKm;
22-
let hoursToMoon = milesToMoon / speed;
23-
let daysToMoon = hoursToMoon / 24;
24-
console.log(shuttleName + " will take " + daysToMoon + " days to reach the Moon.");
25-
// Print the results of the trip to the moon below
3+
if (num % 2 === 0) {
4+
if (num % 2 === 1) {
5+
console.log("odd");
6+
}
7+
}

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 {
Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
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-
71
let launchReady = false;
2+
let crewReady = false;
83
let fuelLevel = 17000;
9-
// let crewStatus = true;
10-
// let computerStatus = 'green';
4+
let crewStatus = true;
5+
let computerStatus = 'green';
116

127
if (fuelLevel >= 20000) {
138
console.log('Fuel level cleared.');
@@ -16,18 +11,20 @@ if (fuelLevel >= 20000) {
1611
console.log('WARNING: Insufficient fuel!');
1712
launchReady = false;
1813
}
14+
console.log("launchReady = ", launchReady);
1915

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-
// }
16+
if (crewStatus && computerStatus === 'green'){
17+
console.log('Crew & computer cleared.');
18+
crewReady = true;
19+
} else {
20+
console.log('WARNING: Crew or computer not ready!');
21+
crewReady = false;
22+
}
23+
console.log("crewReady = ", crewReady);
2724

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-
// }
25+
if (launchReady) {
26+
console.log('10, 9, 8, 7, 6, 5, 4, 3, 2, 1...');
27+
console.log('Liftoff!');
28+
} else {
29+
console.log('Launch scrubbed.');
30+
}

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)