Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

javascript/introduction-to-js-1/first-splash/number-guessing-game.html line 64 is different than any material covered by the tutorial #661

Open
zhayes84 opened this issue Aug 21, 2023 · 3 comments
Labels
area: JavaScript bug Indicates an unexpected problem or unintended behavior. effort: small This task is a small effort. help wanted If you know something about this topic, we would love your help!

Comments

@zhayes84
Copy link

zhayes84 commented Aug 21, 2023

In the tutorial: "A first splash into JavaScript" , the following code block is given as a start point:

function checkGuess() {
  const userGuess = Number(guessField.value);
  if (guessCount === 1) {
    guesses.textContent = "Previous guesses:";
  }
  guesses.textContent = `${guesses.textContent} ${userGuess}`;

  if (userGuess === randomNumber) {
    lastResult.textContent = "Congratulations! You got it right!";
    lastResult.style.backgroundColor = "green";
    lowOrHi.textContent = "";
    setGameOver();
  } else if (guessCount === 10) {
    lastResult.textContent = "!!!GAME OVER!!!";
    lowOrHi.textContent = "";
    setGameOver();
  } else {
    lastResult.textContent = "Wrong!";
    lastResult.style.backgroundColor = "red";
    if (userGuess < randomNumber) {
      lowOrHi.textContent = "Last guess was too low!";
    } else if (userGuess > randomNumber) {
      lowOrHi.textContent = "Last guess was too high!";
    }
  }

  guessCount++;
  guessField.value = "";
  guessField.focus();
}

Upon playing the final version of the game we make, I noticed that upon subsequent playthroughs, after clicking the "Start new game" button, the game no longer displays "Previous guesses:" before each previous guesses' number.

After further inspection, the final code contains this on line 64:

guesses.textContent += userGuess + ' ';

This line is different than any other material in the tutorial and appears to fix the issue I was having with subsequent playthroughs of the game.

@caugner caugner added needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. bug Indicates an unexpected problem or unintended behavior. help wanted If you know something about this topic, we would love your help! effort: small This task is a small effort. area: JavaScript and removed needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. labels Oct 10, 2023
@JohannesMolla
Copy link

@caugner can I work on this ?

@Vidit151003
Copy link

Can I work on this ?

@yashgautam99
Copy link

i can fix this code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: JavaScript bug Indicates an unexpected problem or unintended behavior. effort: small This task is a small effort. help wanted If you know something about this topic, we would love your help!
Projects
None yet
Development

No branches or pull requests

5 participants