简体   繁体   中英

I can't seem to figure out how to fix two lints in my javascript. Can someone help me understand?

I just started javascript and made my first game today! I am very happy with it and in the process of making it lint free.

I'm getting really frustrated, i fixed almost all my mistakes(lints) but there are two I can't seem to fix! I've been trying for over an hour. Could someone please help me solve this? I'm getting frustrated :(

The lints are:

5 'prompt' was used before it was defined. var name = prompt("Hallo Speler, wat is uw naam?.", "naam van speler");

5 Expected an identifier and instead saw '"'. var name = prompt("Hallo Speler, wat is uw naam?.", "naam van speler");

This is my javascript code:

 //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; 

Thanks a lot for taking the time helping me.

xx

The first error is because it does not know where prompt is defined. You can prefix it with window like this: window.prompt(...

Or you could add prompt to the list of "globals" passed in the jshint configuration: http://jshint.com/docs/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM