forked from LaunchCodeEducation/javascript-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
String and Array - Excersise completed
- Loading branch information
1 parent
af86ac4
commit 30098f3
Showing
12 changed files
with
148 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
//Create an array called practiceFile with the following entry: 273.15 | ||
|
||
let practiceFile =[273.15]; | ||
//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. | ||
|
||
practiceFile.push(42); | ||
console.log(practiceFile); | ||
practiceFile.push("hello"); | ||
console.log(practiceFile); | ||
//Use a single .push() to add the following items: false, -4.6, and "87". Print the array to confirm the changes. | ||
practiceFile.push(false,-4.6, "87"); | ||
console.log(practiceFile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
//Arrays can hold different data types, even other arrays! A multi-dimensional array is one with entries that are themselves arrays. | ||
|
||
//1) Define and initialize the arrays specified in the exercise to hold the name, chemical symbol and mass for different elements. | ||
|
||
let element1 = ['hydrogen', 'H', 1.008]; | ||
let element2 = ['helium', 'He', 4.003]; | ||
let element26 = ['iron', 'Fe', 55.85]; | ||
//2) Define the array 'table', and use 'push' to add each of the element arrays to it. Print 'table' to see its structure. | ||
|
||
let table = []; | ||
table.push(element1,element2,element26); | ||
console.log(table); | ||
//3) Use bracket notation to examine the difference between printing 'table' with one index vs. two indices (table[][]). | ||
|
||
console.log(table[1]); | ||
console.log(table[1][1]); | ||
//4) Using bracket notation and the table array, print the mass of element1, the name for element 2 and the symbol for element26. | ||
|
||
console.log(`The mass of element1 is ${table[0][2]}, The name of element2 is ${table[1][0]}, The symbol of elemnt26 is ${table[2][1]}`); | ||
//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. | ||
let tablesOftable=[]; | ||
tablesOftable.push(table); | ||
console.log(tablesOftable[0][1][0]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
let cargoHold = ['oxygen tanks', 'space suits', 'parrot', 'instruction manual', 'meal packs', 'slinky', 'security blanket']; | ||
|
||
//1) Use bracket notation to replace ‘slinky’ with ‘space tether’. Print the array to confirm the change. | ||
|
||
cargoHold.splice(5, 1, "space tether"); | ||
console.log(cargoHold); | ||
//2) Remove the last item from the array with pop. Print the element removed and the updated array. | ||
|
||
console.log(cargoHold.pop()); | ||
console.log(cargoHold); | ||
//3) Remove the first item from the array with shift. Print the element removed and the updated array. | ||
|
||
console.log(cargoHold.shift()); | ||
console.log(cargoHold); | ||
//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. | ||
console.log(cargoHold.unshift(1138)); | ||
console.log(cargoHold.push("20 meters")); | ||
console.log(cargoHold); | ||
|
||
//5) Use a template literal to print the final array and its length. | ||
console.log(`The array ${cargoHold} has a length of ${cargoHold.length}.`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
let day = Wednesday; | ||
console.log(day; | ||
let day = "Wednesday"; | ||
console.log(day); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters