0

When I checked the console I expect avg1 to be replaced by scoreDolphins when it is later logged to console but instead saw avg1. Is there a way to do that inside a function?

const calcAverage = (score1, score2, score3) => {
  return ((score1 + score2 + score3) / 3);
};
const scoreDolphins = (calcAverage(44, 23, 71));
const scoreKoalas = (calcAverage(65, 54, 49));
const scoreDolphins2 = (calcAverage(85, 54, 41));
const scoreKoalas2 = (calcAverage(23, 34, 27));

const checkWinner = function(avg1, avg2) {
  if (avg1 >= avg2 * 2) {
    return ('Dolphins wins (avg1 vs.avg2)');
  } else if (avg2 >= avg1 * 2) {
    return 'Koalas wins (avg2 vs.avg1)';
  } else return 'no team wins';
  console.log(checkWinner(scoreDolphins, scoreKoalas));
  console.log(checkWinner(scoreDolphins2, scoreKoalas2));
};
Amolgorithm
  • 697
  • 2
  • 20
Shunkun
  • 13
  • 3
  • 1
    Variables don't get replaced inside strings. Use a template literal if you want to substitute variables. – Barmar Jul 27 '23 at 04:18

0 Answers0