Invalid or unexpected token error

0

Witam, mam pewien problem z tym kodem :
https://pastebin.com/Z3ix8ktt
Nie odpala się cały kod, tylko w konsoli pojawia się error : Invalid or unexpected token, próbowałem przekopiować ten kod z książki lecz wyskakiwało to samo.

0

U mnie działa. Do zmiany jeden szczegół, Bo jeżeli dasz analuj, to pojawia Ci się, że wygrałeś.

    // Show the answer and congratulate the player
    if (guess !== null) {    
        alert(answerArray.join(" "));
        alert("Good job! The answer was " + word);
    }
0

Dzięki, nie wiem czemu u mnie nie działa ten kod może coś z przeglądarką nie tak ;d

0

Problem jest w linijce 29-30:

 var guess = prompt("Guess a letter, or click Cancel to stop 
playing.");

Jak zapiszesz to w jednej lini to bedzie dzialac:

 var guess = prompt("Guess a letter, or click Cancel to stop ? playing.");
0

Dzięki, jeszcze jedno pytanie, jak chciałbym zrobić licznik prób i jeżeli gracz przekroczy określoną liczbę tych prób to gra się zamyka, czy mógłbym to zrobić w taki sposób?

var guessAmount = 5;
 while (guessAmount>0) {
 // Show the player their progress
 	if(guessAmount[i] !== true){
 		guessAmount--;
 		alert("You have reached the limit of guessing");
 		break;
 	}



według mnie jest to trochę bez sensu, ale nie wiem za bardzo jak zrobić taki licznik ;d

0

Bez większych przeróbek Twojego kodu. Może taki sposób będzie Ci odpowiadać?

let guessAmount = 9;
    
    // The game loop
    while (remainingLetters > 0) {
        // Show the player their progress
        alert(answerArray.join(" "));
        // Get a guess from the player
        var guess = prompt("Guess a letter, or click Cancel to stop playing.");
        
        if (guess === null) {
            // Exit the game loop
            break;
        } else if (guess.length !== 1) {
            alert("Please enter a single letter.");
        } else {
            // Update the game state with the guess
            for (var j = 0; j < word.length; j++) {
                if (word[j] === guess) {
                    answerArray[j] = guess;
                    remainingLetters--;
                }
            }
        }
        guessAmount--;
        
        if (guessAmount === 0) {
            alert("You have reached the limit of guessing");
            guessAmount = (remainingLetters > 0 ) ? 0 : 1; 
            break;
        }
        // The end of the game loop
    }
    
    // Show the answer and congratulate the player
    if (guess !== null && guessAmount > 0) {    
        alert(answerArray.join(" "));
        alert("Good job! The answer was " + word);
    }   
0

Tak, odpowiada ;d dzięki, temat do zamknięcia

1 użytkowników online, w tym zalogowanych: 0, gości: 1