Skip to content

Commit 27a97ba

Browse files
committed
add solutions for JS Ch. 5
1 parent 0345f6f commit 27a97ba

6 files changed

+87
-0
lines changed

Diff for: 5-arrays/23-five-boroughs.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Five Boroughs 🗽
2+
// Codédex
3+
4+
const myNYCDestinations = [
5+
"🗽 Manhattan - Times Square",
6+
"🏟️ The Bronx - Yankee Stadium",
7+
"🎡 Brooklyn - Coney Island",
8+
"✈️ Queens - Astoria Park",
9+
"🌉 Staten Island - Historic Richmond Town"
10+
];
11+
12+
console.log(myNYCDestinations);

Diff for: 5-arrays/24-grocery-trip.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Grocery Trip 🛒
2+
// Codédex
3+
4+
let groceryList = ["🥛 Milk", "🥑 Avocado", "🥚 Eggs ", "🍞 Bread"];
5+
6+
groceryList[2] = "🧈 Butter";
7+
8+
groceryList[4] = "🧼 Laundry Soap"
9+
10+
console.log(groceryList);

Diff for: 5-arrays/25-times-tables.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Times Tables ❌
2+
// Codédex
3+
4+
const multiple = 5;
5+
const numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
6+
7+
for (let i = 0; i < numbers.length; i++) {
8+
console.log(multiple + " x " + i + " = " + multiple * i);
9+
}

Diff for: 5-arrays/26-music-playlist.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Music Playlist 🎵
2+
// Codédex
3+
4+
const musicPlaylist = [
5+
"Tom Sawyer",
6+
"Sabotage",
7+
"I Wanna Dance With Somebody",
8+
"Don't Speak",
9+
"Bulls On Parade",
10+
"Thriller",
11+
"The Breaks",
12+
"Brick",
13+
"Aeroplane Over the Sea",
14+
"Tubthumping"
15+
];
16+
17+
// Remove first element
18+
musicPlaylist.shift();
19+
20+
// Remove last element
21+
musicPlaylist.pop();
22+
23+
// Add to end of array
24+
musicPlaylist.push("Blue (Da Ba Dee)");
25+
26+
// Add to start of array
27+
musicPlaylist.unshift("Gangnam Style", "Harlem Shake");
28+
29+
console.log(musicPlaylist);

Diff for: 5-arrays/27-wheres-waldo.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Where's Waldo 🔍
2+
// Codédex
3+
4+
const characters = ["The Wally Watchers", "Wilma", "Fritz", "Wizard Whitebeard", "Odlaw", "Waldo", "Woof"];
5+
6+
if (characters.includes("Waldo")) {
7+
const waldoIndex = characters.indexOf("Waldo");
8+
console.log("Found Waldo at index " + waldoIndex);
9+
} else {
10+
console.log("Not Found");
11+
}

Diff for: 5-arrays/28-dna.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// DNA 🧬
2+
// Codédex
3+
4+
const dnaPieces = ["A", "C", "G", "T"];
5+
6+
const myDNA = []
7+
8+
for (let i = 0; i < 24; i++) {
9+
const pieceOne = Math.floor(Math.random() * dnaPieces.length);
10+
const pieceTwo = Math.floor(Math.random() * dnaPieces.length);
11+
const pieceThree = Math.floor(Math.random() * dnaPieces.length);
12+
13+
myDNA.push(dnaPieces[pieceOne] + dnaPieces[pieceTwo] + dnaPieces[pieceThree]);
14+
}
15+
16+
console.log(myDNA);

0 commit comments

Comments
 (0)