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.
- Rejestracja:prawie 8 lat
- Ostatnio:ponad 7 lat
- Postów:17
0
edytowany 1x, ostatnio: zetafunction
- Rejestracja:ponad 9 lat
- Ostatnio:około 3 godziny
- Postów:104
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);
}
edytowany 2x, ostatnio: loki121212
- Rejestracja:prawie 8 lat
- Ostatnio:ponad 7 lat
- Postów:17
0
Dzięki, nie wiem czemu u mnie nie działa ten kod może coś z przeglądarką nie tak ;d
edytowany 1x, ostatnio: zetafunction
- Rejestracja:prawie 8 lat
- Ostatnio:ponad 7 lat
- Postów:17
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
edytowany 4x, ostatnio: zetafunction
- Rejestracja:ponad 9 lat
- Ostatnio:około 3 godziny
- Postów:104
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);
}
- Rejestracja:prawie 8 lat
- Ostatnio:ponad 7 lat
- Postów:17
0
Tak, odpowiada ;d dzięki, temat do zamknięcia
Zarejestruj się i dołącz do największej społeczności programistów w Polsce.
Otrzymaj wsparcie, dziel się wiedzą i rozwijaj swoje umiejętności z najlepszymi.