I am new to javascript and I am Confused between these 2 codes.
Can someone tell me what’s the difference between these 2 codes, They both work exactly the same so which one should I use?
THANK YOU:)
const calcAverage = (a, b, c) => ((a + b + c) / 3);
console.log(calcAverage(44, 23, 71))
function chechWinner(avgDolphins, avgKoalas) {
if (avgDolphins >= 2 * avgKoalas) {
return `Dolphins win (${avgDolphins} vs ${avgKoalas})`;
} else if (avgKoalas >= 2 * avgDolphins) {
return `Koalas win (${avgKoalas} vs ${avgDolphins})`;
} else {
return "No team wins.";
}
}
console.log(chechWinner(scoreDolphins, scoreKoalas));
**AND**
function chechWinner(avgDolphins, avgKoalas) {
if (avgDolphins >= 2 * avgKoalas) {
console.log(`Dolphins win (${avgDolphins} vs ${avgKoalas})`);
} else if (avgKoalas >= 2 * avgDolphins) {
console.log(`Koalas win (${avgKoalas} vs ${avgDolphins})`);
} else {
console.log("No team wins.");
}
}
chechWinner(scoreDolphins, scoreKoalas);