본문 바로가기

Programming/JavaScript

Coding Challenge #3 - Compare the team's average scores using if / else statements

const averageScoreOfDolphins = ((96 + 108 + 89) / 3).toFixed([1]);
const averageScoreOfKoalas = ((88 + 91 + 110) / 3).toFixed([1]);

console.log(`The average score of Dolphis is ${averageScoreOfDolphins} and the average score of Koalas is ${averageScoreOfKoalas}`);
// prints The average score of Dolphis is 97.7 and the average score of Koalas is 96.3

if (averageScoreOfDolphins > averageScoreOfKoalas) {
    console.log(`That's why the winner is Dolphis`);
} else if (averageScoreOfDolphins === averageScoreOfKoalas) {
    console.log(`There's no winner. They have the same average score :)`);
} else {
    console.log(`That's why the winner is Koalas`);
}
// prints That's why the winner is Dolphis

'Programming > JavaScript' 카테고리의 다른 글

The Conditional (Ternary) Operator  (0) 2022.08.30
Statements and Expressions  (0) 2022.08.25
The switch Statement  (0) 2022.08.25
Truthy and Falsy Values  (0) 2022.08.21
Type Conversion and Coercion  (0) 2022.08.21