let scoreDolphins = [96,108,89];
let dolphinsAv = 0;
let scoreKoalas = [88,91,110];
let koalasAv = 0;
let findScoreAvD = (scoreDolphins) =>{
for(let i = 0; i < scoreDolphins.length; i++){
dolphinsAv = dolphinsAv + scoreDolphins[i];
}
dolphinsAv = dolphinsAv /3;
//console.log(dolphinsAv);
return dolphinsAv
}
let findScoreAvK = (scoreKoalas) =>{
for(let i = 0; i < scoreKoalas.length; i++){
koalasAv = koalasAv + scoreKoalas[i];
}
koalasAv = koalasAv / 3;
//console.log(koalasAv)
return koalasAv;
}
function announceWin (AvK, AvD){
//console.log(koalasAv);
//console.log(dolphinsAv);
const averageK = AvK;
const averageD = AvD;
console.log(averageK);
console.log(averageD);
if(averageK > averageD){
console.log("Koalas win the trophy");
}if(averageK < averageD){
console.log("Dolphins win the trophy");
}if(averageK === averageD){
console.log("Both win the trophy");
}else{
console.log('didnt work')
}
// switch(averageK, averageD){
// case(averageK > averageD):
// console.log("Koalas win the trophy");
// break;
// case(averageK < averageD):
// console.log("Dolphins win the trophy");
// break;
// case(averageK === averageD):
// console.log("Both win the trophy");
// break;
// default: console.log('did not work');
// }
}
announceWin(findScoreAvK(scoreKoalas), findScoreAvD(scoreDolphins));
I expected the switch to work similarly to the if statement, why is it not the same logic here? its been bugging me for like an hour now and i cant figure it out... its for a coding challenge
CHALLENGE #3 There are two gymnastics teams: Dolphins and Koalas. They compete against each other 3 times. The winner with the highest average score wins a trophy!
Your tasks:
Calculate the average score for each team, using the test data included below. The average score for Dolphins should be assigned to the scoreDolphins variable, and the average score of Koalas should be assigned to the scoreKoalas variable.
Compare the team's average scores to determine the winner of the competition, and print to the console:
"Dolphins win the trophy" if Dolphins win, or
"Koalas win the trophy" if Koalas win, or
"Both win the trophy" if their average scores are equal.
TEST DATA: Dolphins scored 96, 108, and 89. Koalas scored 88, 91, and 110.