Skip to content

Commit 1c97921

Browse files
committed
add solutions for JS Ch. 6
1 parent 43dae2a commit 1c97921

File tree

5 files changed

+77
-0
lines changed

5 files changed

+77
-0
lines changed

6-functions/29-greetings.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Greetings 👋
2+
// Codédex
3+
4+
function greetings() {
5+
for (let i = 1; i <= 3; i++) {
6+
console.log(i);
7+
}
8+
console.log("Hello, everyone!");
9+
}
10+
11+
greetings();

6-functions/30-blast-off.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Blast Off 🚀
2+
// Codédex
3+
4+
function countdown() {
5+
const randomNumber = Math.floor(Math.random() * 10) + 1;
6+
7+
for (let i = 10; i > 0; i--) {
8+
console.log(i);
9+
}
10+
11+
return "Blast Off! 🚀";
12+
}
13+
14+
console.log(countdown());

6-functions/31-e-mc-2.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// E = mc² 🌌
2+
// Codédex
3+
4+
function relativityTheory(mass) {
5+
const speedOfLight = 3e8;
6+
7+
const energy = mass * speedOfLight ** 2;
8+
9+
return energy
10+
}
11+
12+
relativityTheory(123.4);

6-functions/32-clout.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// YouTube Stats ▶️
2+
// Codédex
3+
4+
const weeklyYouTubeStats = [2.3, 4.8, 6.7, 7.0, 1.9, 8.4, 5.2];
5+
6+
function mean() {
7+
let totalViews = 0;
8+
9+
for (let i = 0; i < weeklyYouTubeStats.length; i++) {
10+
totalViews += weeklyYouTubeStats[i];
11+
}
12+
13+
return totalViews / weeklyYouTubeStats.length;
14+
}
15+
16+
function median() {
17+
const sortedStats = weeklyYouTubeStats.sort();
18+
const middleIndex = Math.floor(weeklyYouTubeStats.length / 2);
19+
20+
return sortedStats[middleIndex];
21+
}
22+
23+
console.log(mean());
24+
console.log(median());

6-functions/33-palindrome.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Palindrome ↔️
2+
// Codédex
3+
4+
function isPalindrome(word) {
5+
let reversedWord = "";
6+
7+
let lowerCaseWord = word.toLowerCase();
8+
9+
for (let i = lowerCaseWord.length - 1; i >= 0; i--) {
10+
reversedWord += lowerCaseWord[i];
11+
}
12+
13+
return reversedWord == lowerCaseWord;
14+
}
15+
16+
console.log(isPalindrome("Racecar"));

0 commit comments

Comments
 (0)