forked from LaunchCodeEducation/javascript-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrays excercises.js
70 lines (47 loc) · 1.93 KB
/
arrays excercises.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//Create an array that can hold 4 items name practiceFile.
//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.
//Use a SetValue to add the items "false", and "-4.6" to the array. Print the array to confirm the changes.
let practiceFile = [273.15];
practiceFile.push((42) + ("hello"));
console.log(practiceFile);
practiceFile.push(false, -4.6, "87");
console.log(practiceFile);
let cargoHold = ['oxygen tanks', 'space suits', 'parrot', 'instruction manual', 'meal packs', 'slinky', 'security blanket'];
cargoHold[5] = ('space tether')
console.log(cargoHold);
cargoHold.pop('security blanket');
console.log(cargoHold);
cargoHold.shift('oxygen tanks');
console.log(cargoHold);
cargoHold.push('20 meters');
cargoHold.unshift(1138);
console.log(cargoHold);
console.log(`The array ${cargoHold} has a length of ${cargoHold.length}.`);
cargoHold.splice(3,0,'keys');
console.log(cargoHold);
cargoHold.splice(2,3,'cat','fob','string cheese');
console.log(cargoHold);
holdCabinet1 = ['duct tape', 'gum', 3.14, false, 6.022e23]
holdCabinet2 = ['orange drink', 'nerf toys', 'camera', 42, 'parsnip']
console.log(holdCabinet1.concat(holdCabinet2));
console.log(holdCabinet1);
holdCabinet1.reverse();
holdCabinet2.sort();
console.log(holdCabinet1);
console.log(holdCabinet2);
let str = ("In space, no one can hear you code.");
str.split();
console.log(str.split());
console.log(str.split('e'));
console.log(str.split(' '));
console.log(str.split(''));
arr = ['B', 'n', 'n', 5];
console.log(arr.join())
console.log(arr.join('a'))
console.log(arr.join(''))
console.log(arr.join(' '))
let element1 = ['hydrogen', 'H', 1.008]
let element2 = ['helium', 'He', 4.003]
let element26 = ['iron', 'Fe', 55.85]
let table = (element1 + element2 + element26)
console.log(table[1], table[1][1]);