簡體   English   中英

JS -> Uncaught ReferenceError: Dolphins 未定義

[英]JS -> Uncaught ReferenceError: Dolphins is not defined

所以我試圖在 JS 方面做得更好,因為我的語言非常薄弱,所以參加了一門課程並且我正在接受其中一個挑戰。 我確信可能有一種更簡單的方法來獲得我對這個任務的答案,但這不是我在這里尋找的,我收到標題中描述的錯誤但不確定為什么......當我運行腳本時在 index.html 文件上我收到錯誤:

未捕獲的 ReferenceError:未定義 Dolphins

對於導致此錯誤的原因,我真的很感激任何幫助:)

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}`)
}

您的問題是,您還沒有定義變量Dolphines 所以 JavaScript 認為, Dolphines是一個變量。 但它不是一個,因為它沒有在任何地方定義。

由於您可能要為變量 teamA 賦值,因此應該將Dolphines用雙引號 (") 括起來。當然,您也應該將Koalas用雙引號括起來。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM