Skip to content
This repository was archived by the owner on Oct 1, 2025. It is now read-only.

Commit 3e05cda

Browse files
committed
feat: Challenge 5 and 6 of JS Fundamentals Done
1 parent d102ec3 commit 3e05cda

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const calcAverage = (score1, score2, score3) => {
2+
let avr = (score1 + score2 + score3) / 3;
3+
console.log(avr);
4+
return avr;
5+
};
6+
7+
8+
function checkWinner(avrTeam1, avrTeam2, nameTeam1, nameTeam2) {
9+
if (avrTeam1 >= 2 * avrTeam2) {
10+
console.log(`${nameTeam1} win (${avrTeam1} vs. ${avrTeam2})`);
11+
} else if (avrTeam2 >= 2 * avrTeam1) {
12+
console.log(`${nameTeam2} win (${avrTeam2} vs. ${avrTeam1})`);
13+
} else {
14+
console.log("No team wins...");
15+
}
16+
}
17+
18+
let scoreDolphins = [44, 23, 71];
19+
let scoreKoalas = [23, 34, 27];
20+
21+
let avgDolphins = calcAverage(scoreDolphins[0], scoreDolphins[1], scoreDolphins[2]);
22+
let avgKoalas = calcAverage(scoreKoalas[0], scoreKoalas[1], scoreKoalas[2]);
23+
24+
checkWinner(avgDolphins, avgKoalas, "Dolphins", "Koalas");
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function calcTip(bill) {
2+
if (bill >= 50 && bill <= 300) {
3+
return bill * 0.15
4+
} else {
5+
return bill * 0.2;
6+
}
7+
}
8+
9+
calcTip(100);
10+
11+
let bills = [125, 555, 44]
12+
let tips = [];
13+
let totals = [];
14+
15+
for (let i = 0; i < bills.length; i++) {
16+
tips.push(calcTip(bills[i]));
17+
totals.push(tips[i] + bills[i]);
18+
}

0 commit comments

Comments
 (0)