I am new to javascript. I'm trying to code a simple program which has 2 variables, each one contains an average number of some calculations, and using if else it should print the variable which contains the higher average as the winner.
without using toFixed() there is no problem, the higher variable is the winner and its printed out, but when I use toFixed(), it prints the lower variable, not the higher one. why is that? picture of the problem
here is the code:
const avgDolphins = ((96 + 108 + 89) / 3).toFixed(2);
const avgKoalas = ((88 + 91 + 911) / 3).toFixed(2);
console.log(`dolphins = ${avgDolphins} \nkoalas = ${avgKoalas}`)
if (avgDolphins > avgKoalas) {
console.log(`Team Dolphins WON! with ${avgDolphins} Average score!`);
} else if (avgKoalas > avgDolphins) {
console.log(`Team Koalas WON! with ${avgKoalas} Average score!`);
} else {
console.log(`DRAW! Both teams got the same average score which is ${avgKoalas}`);
}