Skip to content

Commit 3d006f0

Browse files
committed
part6
1 parent 5db6d93 commit 3d006f0

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

arrays/exercises/part-six-arrays.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
//Arrays can hold different data types, even other arrays! A multi-dimensional array is one with entries that are themselves arrays.
22

33
//1) Define and initialize the arrays specified in the exercise to hold the name, chemical symbol and mass for different elements.
4-
4+
let element1 = ['hydrogen', 'H', 1.008]
5+
let element2 = ['helium', 'He', 4.003]
6+
let element26 = ['iron', 'Fe', 55.85]
57
//2) Define the array 'table', and use 'push' to add each of the element arrays to it. Print 'table' to see its structure.
6-
8+
let table=[]
9+
table.push(element1);
10+
table.push(element2);
11+
table.push(element26);
12+
console.log(table);
713
//3) Use bracket notation to examine the difference between printing 'table' with one index vs. two indices (table[][]).
8-
14+
console.log(table[1]);
15+
console.log(table[0,1]);
916
//4) Using bracket notation and the table array, print the mass of element1, the name for element 2 and the symbol for element26.
1017

1118
//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.

0 commit comments

Comments
 (0)