Skip to content

Commit 54c5d4d

Browse files
committed
Loops
1 parent 9e88293 commit 54c5d4d

File tree

19 files changed

+390
-10
lines changed

19 files changed

+390
-10
lines changed

arrays/exercises/https:/github.com/dbenion9/javascript-projects.git

Whitespace-only changes.

arrays/exercises/part-five-arrays.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,27 @@ let arr = ['B', 'n', 'n', 5];
33

44
//1) Use the split method on the string to identify the purpose of the parameter inside the ().
55

6+
let words = str.split(' ');
7+
console.log(words);
8+
69
//2) Use the join method on the array to identify the purpose of the parameter inside the ().
710

11+
let joinedString = arr.joint('a');
12+
console.log(joinedString);
13+
814
//3) Do split or join change the original string/array?
915

16+
console.log(str);
17+
console.log(arr);
18+
1019
//4) We can take a comma-separated string and convert it into a modifiable array. Try it! Alphabetize the cargoHold string, and then combine the contents into a new string.
1120
let cargoHold = "water,space suits,food,plasma sword,batteries";
21+
22+
let cargoArry = cargoHold. split(',');
23+
console.log(cargoArray);
24+
25+
cargoArray.sort();
26+
console.log(cargoArry);
27+
28+
let sortedCargoHold = cargoArray.join(',');
29+
console.log(sortedCargoHold);

arrays/exercises/part-four-arrays.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@ let holdCabinet2 = ['orange drink', 'nerf toys', 'camera', 42, 'parsnip'];
55

66
//1) Print the result of using concat on the two arrays. Does concat alter the original arrays? Verify this by printing holdCabinet1 after using the method.
77

8+
let combinedCabinets = holdCabinet1.concat(holdCabinet2);
9+
console.log(combinedCabinets);
10+
console.log(holdCabinet1);
11+
812
//2) Print a slice of two elements from each array. Does slice alter the original arrays?
913

14+
let sliceCabinet1 = holdCabinet1.slice(1, 3);
15+
console.log(sliceCabinet1);
16+
let sliceCabinet2 = holdCabinet2.slice(1, 3);
17+
console.log(sliceCabinet2);
18+
console.log(holdCabinet1);
19+
console.log(holdCabinet2);
20+
1021
//3) reverse the first array, and sort the second. What is the difference between these two methods? Do the methods alter the original arrays?
22+
23+
let reversedCabinet1 = holdCabinet1.reverse();
24+
console.log(reversedCabinet1);
25+
let soretedCabinet2 = holdCabinet2.sort();
26+
console.log(soretedCabinet2);
27+
console.log(holdCabinet1);
28+
console.log(holdCabinet2);

arrays/exercises/part-one-arrays.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
//Create an array called practiceFile with the following entry: 273.15
22

3+
let practiceFile = [273.15];
4+
35
//Use the bracket notation method to add "42" and "hello" to the array. Add these new items one at a time. Print the array after each step to confirm the changes.
46

7+
practiceFile[1] = 42;
8+
console.log(practiceFile);
9+
10+
practiceFile[2] = 'hello';
11+
console.log(practiceFile);
12+
513
//Use a single .push() to add the following items: false, -4.6, and "87". Print the array to confirm the changes.
14+
15+
practiceFile.push(false, -4.6, '87');
16+
console.log(practiceFile);

arrays/exercises/part-six-arrays.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,56 @@
22

33
//1) Define and initialize the arrays specified in the exercise to hold the name, chemical symbol and mass for different elements.
44

5+
let hydrogen = ['Hydrogen', 'H', 1.080];
6+
let helium = ['Helium', 'He', 4.0026];
7+
let lithium = ['Lithium', 'Li', 6.94];
8+
59
//2) Define the array 'table', and use 'push' to add each of the element arrays to it. Print 'table' to see its structure.
610

11+
let table = [];
12+
table.push(hydrogen);
13+
table.push(helium);
14+
table.push(lithium);
15+
console.log(table);
16+
717
//3) Use bracket notation to examine the difference between printing 'table' with one index vs. two indices (table[][]).
818

19+
console.log(table[0]);
20+
21+
console.log(table[0][0]);
22+
console.log(table[0][1]);
23+
console.log(table[0][2]);
24+
25+
26+
27+
928
//4) Using bracket notation and the table array, print the mass of element1, the name for element 2 and the symbol for element26.
1029

30+
console.log('The mass of Hydrogen is table[0].');
31+
console.log('The name of the second element is [1][0].');
32+
console.log('The symbol is Lithium is [1].');
33+
34+
1135
//5) 'table' is an example of a 2-dimensional array. The first “level” contains the element arrays, and the second level holds the name/symbol/mass values. Experiment! Create a 3-dimensional array and print out one entry from each level in the array.
36+
37+
let threeDimArray = [
38+
[
39+
['a1', 'a2', 'a3'],
40+
['b1', 'b2', 'b3'],
41+
['c1', 'c2', 'c2']
42+
],
43+
[
44+
['d1', 'd2', 'd3'],
45+
['e1', 'e2', 'e3'],
46+
['f1', 'f2', 'f3']
47+
],
48+
[
49+
['g1', 'g2', 'g3'],
50+
['h1', 'h2', 'h3'],
51+
['i1', 'i2', 'i2']
52+
]
53+
];
54+
55+
console.log(threeDimArray[1]);
56+
console.log(threeDimArray[1][2]);
57+
console.log(threeDimArray[1][2][1]);

arrays/exercises/part-three-arrays.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ let cargoHold = [1138, 'space suits', 'parrot', 'instruction manual', 'meal pack
44

55
//1) Insert the string 'keys' at index 3 without replacing any other entries.
66

7+
cargoHold.splice(3, 0, 'keys');
8+
console.log(cargoHold);
9+
710
//2) Remove ‘instruction manual’ from the array. (Hint: indexOf is helpful to avoid manually counting an index).
811

12+
let index = cargoHold.indexOf('instruction manual');
13+
14+
if (index !== -1) {
15+
cargoHold.splice(index, 1);
16+
}
17+
console.log(cargoHold);
918
//3) Replace the elements at indexes 2 - 4 with the items ‘cat’, ‘fob’, and ‘string cheese’.
19+
20+
cargoHold.splice(2, 3, 'cat', 'fob', 'string cheese');
21+
console.log(cargoHold);

arrays/exercises/part-two-arrays.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,30 @@ let cargoHold = ['oxygen tanks', 'space suits', 'parrot', 'instruction manual',
22

33
//1) Use bracket notation to replace ‘slinky’ with ‘space tether’. Print the array to confirm the change.
44

5+
cargo[5] = 'space tether';
6+
console.log(cargoHold);
7+
58
//2) Remove the last item from the array with pop. Print the element removed and the updated array.
69

10+
let removedItem = cargoHold.pop();
11+
console.log(removedItem);
12+
consi=ole.log(cargoHold);
13+
714
//3) Remove the first item from the array with shift. Print the element removed and the updated array.
815

16+
let removedFirstItem = cargoHold.shift();
17+
console.log(removedFirstItem);
18+
console.log(cargoHold);
19+
920
//4) Unlike pop and shift, push and unshift require arguments inside the (). Add the items 1138 and ‘20 meters’ to the the array - the number at the start and the string at the end. Print the updated array to confirm the changes.
1021

22+
cargoHold. unshift(1138);
23+
console.log(cargoHold);
24+
25+
cargoHold.push('20 meters');
26+
console.log(cargoHold);
27+
1128
//5) Use a template literal to print the final array and its length.
29+
30+
console.log( 'The final array is [cargoHold.join(',')] and its length is cargoHild.length.');
31+

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,27 @@ if (engineIndicatorLight === "green") {
99
} else {
1010
console.log("engines are off");
1111
}
12+
let engineIndicatorLight = "red blinking";
13+
let spaceSuitsOn = true;
14+
let shuttleCabinReady =true;
15+
let crewStatus = spaceSuitsOn && shuttleCabinReady;
16+
let computerStatusCode = 200;
17+
let shuttleSpeed = 15000;
18+
19+
if (engineIndicatorLight === "green") {
20+
console.log("engine have started");
21+
}else if ("eengineIndicatorLight === "green blinking") {
22+
console.log("engines are preparing to start");
23+
}else {
24+
console.log("engines are off");
25+
}
26+
}
27+
28+
}
29+
}
30+
}
31+
}
32+
}
33+
}
34+
}
35+
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,23 @@ let shuttleSpeed = 15000;
1919
// 4) PREDICT: Do the code blocks shown in the 'predict.txt' file produce the same result?
2020

2121
console.log(/* "Yes" or "No" */);
22+
23+
if (crewStatus) {
24+
console.log("Crew Ready");
25+
} else {
26+
console.log("Crew Not Ready");
27+
}
28+
}if (computerStatusCode === 200) {
29+
console.log("Please stand by. Computer is rebooting.");
30+
} else if (computerStatusCode === 400) {
31+
console.log("Success! Computer online.");
32+
} else {
33+
console.log("ALERT: Computer offline!");
34+
}
35+
}if (shuttleSpeed > 17500) {
36+
console.log("ALERT: Escape velocity reached!");
37+
} else if (shuttleSpeed < 8000) {
38+
console.log("ALERT: Cannot maintain orbit");
39+
} else {
40+
console.log("Stable speed.");
41+
}

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,54 @@ f) Otherwise, print "Fuel and engine status pending..." */
2222

2323
/* 6) b) Code the following if/else check:
2424
If fuelLevel is above 20000 AND engineIndicatorLight is NOT red blinking OR commandOverride is true print "Cleared to launch!" Else print "Launch scrubbed!" */
25+
26+
if (fuelLevel < 1000 || engineTemperature > 3500 || engineIndicatorLight === "red blinking"){
27+
console.log(ENGINE FAILURE IMMIENT!");
28+
} else if (fuelLevel <= 5000 || engineTemperature > 2500){
29+
console.log("Check fuel level. Engines running hot.");
30+
} else if (fuelLevel > 20000 && engineTemperture <+ 2500){
31+
console.log("Full tank. Engines good.");
32+
} else if (fuelLevel > 10000 && engineTemperature <= 2500){
33+
console.log("Fuel level above 50%. Engines are good.");
34+
} else if (fuelLevel > 5000 && engineTemperature <= 2500){
35+
console.log("Fuek level above 25%. Engines good.");
36+
} else {
37+
console.log("Fuel and engines status pendning...");
38+
}
39+
40+
let commandOverride = true; || or false
41+
}
42+
if (commandOverride)
43+
{
44+
return true;
45+
} else {
46+
return fuelCheck && engineCheck;
47+
}
48+
let canLaunch = ShouldLaunch (commandOverride, fuelCheck, engineCheck);
49+
console.log("Shuttle launch status:", canLaunch);
50+
51+
let fuelCheck = false;
52+
53+
if (commandOverride)
54+
{
55+
return true;
56+
} else {
57+
return fuelCheck && engineCheck;
58+
}
59+
}
60+
let canLaunch = shouldLaunch(commandOverride, fuelCheck, engineCheck);
61+
console.log("Shuttle launch status:",
62+
canLaunch);
63+
if (fuelLevel > 20000 ||engineIndicatorLight == "NOT red blinking" || commandOverride = "Cleared to launch".);
64+
console.log("Cleared to Launch.");
65+
} else if ("Launch scrubbed.");
66+
67+
)
68+
}
69+
}
70+
}
71+
}
72+
}
73+
})
74+
})
75+
}

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,27 @@
88

99
// Calculate a trip to the moon below
1010

11-
// Print the results of the trip to the moon below
11+
// Print the results of the trip to the moon below
12+
13+
let shuttleName = 'Determination';
14+
let shuttleSpeedMph = 17500;
15+
let distanceToMarsKm = 225000000;
16+
let distanceToMarsKm = 38400;
17+
const milesPerKm = 0.621;
18+
19+
console.log(typeof shuttleName);
20+
console.log(typeof shuttleSpeedMph);
21+
console.log(typeof distanceToMarsKm);
22+
console.log(distanceToMarsKm);
23+
console.log(milesPerKm);
24+
25+
let milesToMars =255000000 * 0.621;
26+
let hoursToMars =13972500 * 17500;
27+
let daysToMars = 798428571 / 24
28+
29+
console.log(shuttleName + " will take" + ' days ti reach Mars. ");
30+
31+
let milesToMoon = 384400 * 0.621
32+
let hoursToMoon = 384400621 / 17500
33+
let daysToMoon =219657498 / 24
34+
console.log(Determination + "will take " + 219657498 + "days to reach the Moon.");

errors-and-debugging/exercises/Debugging1stSyntaxError.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,15 @@ if (fuelLevel >= 20000 {
1010
} else {
1111
console.log('WARNING: Insufficient fuel!');
1212
launchReady = false;
13+
}
14+
let launchReady = false;
15+
let fuelLevel = 17000;
16+
17+
if (fuelLevel >= 20000) {
18+
console.log('Fuel level cleared.');
19+
launchReady = true'
20+
} else {
21+
console.log('WARNING: Insufficent fuel!');
22+
launchReady = false;
23+
}
1324
}

errors-and-debugging/exercises/DebuggingLogicErrors1.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ if (launchReady) {
2929
console.log('Liftoff!');
3030
} else {
3131
console.log('Launch scrubbed.');
32-
}
32+
}
33+
It did not return. I recieved a syntax error.

0 commit comments

Comments
 (0)