我刚开始使用JavaScript,今天就做了我的第一场比赛!我对此感到非常满意,并希望它不掉毛。

我真的很沮丧,我几乎解决了所有错误(毛发),但有两个我似乎无法解决!我已经尝试了一个多小时。有人可以帮我解决这个问题吗?我很沮丧:(

棉绒是:

在定义前使用了5个“提示”。 var name =提示符(“Hallo Speler,wat是uw naam吗?”,“naam van speler”);

5需要一个标识符,而不是'''。var name =提示符(“Hallo Speler,wat是uw naam?。”,“naam van speler”);

这是我的JavaScript代码:

//Schrijft functie begin spel. value van de input wordt een string. Opnieuw knop wordt disabled.



var name = prompt("Hallo Speler, wat is uw naam?.", "naam van speler");

var data = [
        [0, 11, "Een hele goede morgen,"],
        [12, 17, "Goede middag,"],
        [18, 24, "Goede avond"]
    ],
    hr = new Date().getHours();

for (var i = 0; i < data.length; i++) {
    if (hr >= data[i][0] && hr <= data[i][1]) {
        document.getElementById('welkom').innerHTML = data[i][2] + " " + name;
    }
}


function beginspel() {



    document.getElementById("input_txt").value = "";

    document.getElementById("input_txt").focus();

    document.getElementById("input_txt").disabled = false;
    document.getElementById("guess_btn").disabled = false;
    document.getElementById("playAgain_btn").disabled = true;

    //Tekst weergeeft op het begin informatie over wat je moet doen.
    document.getElementById("message_txt").innerHTML = "Kies een nummer tussen 1 en 100.";

    //nummer van de computer wordt berekend.
     randomNumber = Math.ceil(Math.random() * 100);

    //variabele input is de tekst van input_txt
    input = document.getElementById("input_txt");


    var clicks = 0; // sets a global variable
    // when the window loads

    document.getElementById("guess_btn").addEventListener("click", function() {
        //The above creates an event listener to tell the
        //script what to do when someone clicks on an element
        //with the id "button"

        clicks++; // adds 1 to variable clicks
        document.getElementById('aantalKlik').innerHTML = "U heeft " + clicks + " keer geraden!"; // displays clicks popup
    })



}



var guess_btn = document.getElementById('guess_btn');
guess_btn.addEventListener('click', guessNumber);

var playAgain_btn = document.getElementById('playAgain_btn');
playAgain_btn.addEventListener('click', beginspel);




function guessNumber() {
   guess = document.getElementById("input_txt").value;

    document.getElementById("input_txt").focus();




    if (guess === "") {
        document.getElementById("message_txt").innerHTML = "0 is te laag. Probeer opnieuw!";
    } else if (guess > randomNumber) {
        document.getElementById("message_txt").innerHTML = guess + " is te hoog. Probeer opnieuw!";
        input_txt.value = "";
    } else if (guess < randomNumber) {
        document.getElementById("message_txt").innerHTML = guess + " is te laag. Probeer opnieuw!"
        input_txt.value = "";
    } else {
        document.getElementById("message_txt").innerHTML = "Je hebt goed geraden! Het nummer is " + guess + ".";
        input_txt.value = "";




        endGame();
    }


}

function endGame() {
    document.getElementById("input_txt").disabled = true;
    document.getElementById("guess_btn").disabled = true;
    document.getElementById("playAgain_btn").disabled = false;
}

window.onload = beginspel;


非常感谢您抽出宝贵的时间来帮助我。

xx

最佳答案

第一个错误是因为它不知道prompt的定义位置。您可以像这样用window作为前缀:window.prompt(...
或者,您可以将prompt添加到在jshint配置中传递的“全局变量”列表中:http://jshint.com/docs/

09-27 05:11