未捕获的语法错误:未定义文档

时间:2018-12-31 16:16:07

标签: javascript

我不明白为什么我会不断收到此错误-

  

未捕获的语法错误:未定义文档”

我是Stack Overflow的新手,希望我能正确地提出这个问题。

let  textArea = doucment.getElementById('text-area'),
     newGameButton = document.getElementById('new-game-button'),
     hitButton = document.getElementById('hit-button'),
     stayButton = document.getElementById('stay-button');


hitButton.style.display = 'none';
stayButton.style.display = 'none';
showStatus();


newGameButton.addEventListener('click', function () {  
    gameStarted = true;
    gameOver = false;
    playerWon = false;

    deck = createDeck();
    shuffleDeck(deck);
    dealerCards = [getNextCard(), getNextCard() ];
    playerCards = [getNextCard(), getNextCard() ];

    newGameButton.style.display = 'none';
    hitButton.style.display = 'inline';
    stayButton.style.display = 'inline';
    showStatus();
});

我在HTML正文部分的末尾添加了<script src="script.js"></script>标签。我正在使用VS Code编辑器,所以也许我弄乱了设置或其他内容?

1 个答案:

答案 0 :(得分:-2)

您在第一行中拼写了“文档”。您可以创建一个变量来避免输入错误。

var d = document;

let  textArea = d.getElementById('text-area'),
     newGameButton = d.getElementById('new-game-button'),
     hitButton = d.getElementById('hit-button'),
     stayButton = d.getElementById('stay-button');


hitButton.style.display = 'none';
stayButton.style.display = 'none';
showStatus();


newGameButton.addEventListener('click', function () {  
    gameStarted = true;
    gameOver = false;
    playerWon = false;

    deck = createDeck();
    shuffleDeck(deck);
    dealerCards = [getNextCard(), getNextCard() ];
    playerCards = [getNextCard(), getNextCard() ];

    newGameButton.style.display = 'none';
    hitButton.style.display = 'inline';
    stayButton.style.display = 'inline';
    showStatus();
});