Home > Mobile >  JS -> Uncaught ReferenceError: Dolphins is not defined
JS -> Uncaught ReferenceError: Dolphins is not defined

Time:11-21

So I'm trying to get better at JS as I am very weak in the language so took a course and I'm on one of the challenges. I'm sure there is probably an easier way to get my answers on this task but that's not what I'm looking for here, I'm getting the error described in the title but not sure why... when I run the script on index.html file I get the error:

Uncaught ReferenceError: Dolphins is not defined

Any help I would really appreciate it on what is causing this error :)

const teamA = Dolphins;
const teamB = Koalas;

const avgScoreDolphins = 96   108   89 / 3;
console.log(avgScoreDolphins)

const avgScoreKoalas = 88   91   110 / 3;
console.log(avgScoreKoalas)

if (avgScoreDolphins >= avgScoreKoalas) {
    console.log(`The winning team is ${teamA}`)
} else if (avgScoreKoalas >= avgScoreDolphins) {
    console.log(`The winning team is ${teamB}`)
}
else (avgScoreDolphins === avgScoreKoalas); {
    console.log(`The competition has ended in a draw with ${teamA} and ${teamB}`)
}
const teamA = Dolphins;
const teamB = Koalas;

const avgScoreDolphins = 96   108   89 / 3;
console.log(avgScoreDolphins)

const avgScoreKoalas = 88   91   110 / 3;
console.log(avgScoreKoalas)

if (avgScoreDolphins >= avgScoreKoalas) {
    console.log(`The winning team is ${teamA}`)
} else if (avgScoreKoalas >= avgScoreDolphins) {
    console.log(`The winning team is ${teamB}`)
}
else (avgScoreDolphins === avgScoreKoalas); {
    console.log(`The competition has ended in a draw with ${teamA} and ${teamB}`)
}

CodePudding user response:

Your problem is, that you haven't defined the variable Dolphines yet. So JavaScript thinks, that Dolphines is a variable. But it isn't one because it isn't defined anywhere.

Since you probably want to assign a value to the variable teamA, you should wrap Dolphines with double quotes ("). Of course, you should also wrap Koalas in double quotes.

const teamA = "Dolphins";
const teamB = "Koalas";
  • Related