Skip to content

Commit 0434992

Browse files
committed
part 2 done
1 parent e9b007b commit 0434992

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

arrays/exercises/part-two-arrays.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,25 @@ 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+
cargoHold[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+
console.log(cargoHold.pop());
11+
console.log(cargoHold);
12+
713
//3) Remove the first item from the array with shift. Print the element removed and the updated array.
814

15+
console.log(cargoHold.shift());
16+
console.log(cargoHold);
17+
918
//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.
1019

20+
cargoHold.unshift(1138);
21+
cargoHold.push("20 meters");
22+
console.log(cargoHold);
23+
1124
//5) Use a template literal to print the final array and its length.
25+
26+
console.log(`The array cargoHold:\n[${cargoHold}]\nis ${cargoHold.length} elements long.`)

0 commit comments

Comments
 (0)