Skip to content

Commit 67e4620

Browse files
committed
array part2
1 parent e9b164a commit 67e4620

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

arrays/exercises/part-one-arrays.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
//Create an array called practiceFile with the following entry: 273.15
2+
let practiceFile = ["273.15."];
23

34
//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.
4-
5+
practiceFile.push("42");
6+
practiceFile.push("hello");
7+
console.log(practiceFile);
58
//Use a single .push() to add the following items: false, -4.6, and "87". Print the array to confirm the changes.
9+
practiceFile.push(`false, -4.6,"87"`)
10+
console.log(practiceFile);

arrays/exercises/part-two-arrays.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
let cargoHold = ['oxygen tanks', 'space suits', 'parrot', 'instruction manual', 'meal packs', 'slinky', 'security blanket'];
22

33
//1) Use bracket notation to replace ‘slinky’ with ‘space tether’. Print the array to confirm the change.
4-
4+
cargoHold.splice(5,1,"space tether");
5+
console.log(cargoHold);
56
//2) Remove the last item from the array with pop. Print the element removed and the updated array.
7+
console.log(cargoHold.pop(),cargoHold);
8+
9+
10+
611

712
//3) Remove the first item from the array with shift. Print the element removed and the updated array.
13+
console.log(cargoHold.shift(),cargoHold);
14+
15+
//4) Unlike pop and shift, push and unshift require arguments inside the ().
16+
// Add the items 1138 and ‘20 meters’ to the the array - the number at the start and the string at the end.
17+
//Print the updated array to confirm the changes.
18+
cargoHold.push('20 meters');
19+
cargoHold.unshift(42);
20+
console.log(cargoHold);
821

9-
//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.
1022

1123
//5) Use a template literal to print the final array and its length.
24+
console.log(cargoHold,cargoHold.length);

how-to-write-code/consolelogexamples01.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

2-
);
2+
3+
34
console.log("What","do","commas","do?");
45
console.log("Does", "adding", "space", "matter?");
56
console.log('Launch' + 'Code');

0 commit comments

Comments
 (0)