Number Guessing Game - Build a Number Guessing Game

Tell us what’s happening:

Final submission is failing 2 tests yet my code works as expected. Please assist. I have pasted my code below:

Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36

Challenge Information:

Number Guessing Game - Build a Number Guessing Game

Welcome to the forum @michaelmainacodes

Which two tests are you failing?

I changed the category from freeCodeCamp Support to Backend Development to better reflect the nature of the post.

Happy coding

1 Like

Thank you for the welcome Teller.

The following 2 are failing:
8. If that username has been used before, it should print Welcome back, <username>! You have played <games_played> games, and your best game took <best_game> guesses. , with <username> being a users name from the database, <games_played> being the total number of games that user has played, and <best_game> being the fewest number of guesses it took that user to win the game

  1. When the secret number is guessed, your script should print You guessed it in <number_of_guesses> tries. The secret number was <secret_number>. Nice job! and finish running
  1. After printing "higher or lower than that", what happens?

Happy coding

In either instance, it requests my next guess until I reach the correct #.

Please see below example from just now:

are you counting all tryes? even the ones with invalid numbers?

Yes. In case something happens, I count it as a try, and the numeric columns are set to 0.

here:

while true
do
  read GUESS


  if ! is_integer "$GUESS"
  then
    echo "That is not an integer, guess again:"
    continue
  fi


  GUESSES=$((GUESSES + 1))

doesn’t the continue bring to next iteration? meaning the increase of GUESSES is not done in the case the guess is not an integer?

Sorry. My mistake there. You are right.

So then that iteration will run in the while loop until the secret number is gotten. Which is catered for in the next set of if statements.

Any idea what I might be missing to lead to both tests failing?

you need to count all guesses, even those with invalid values, have you fixed that already?

Yes I have. Please see below:

and the tests now still say the same thing?

Yes. Unfortunately.

I’ve even tried reorganizing the code as shown below:

Still not passing them.

Had to refactor my code and used a different approach. Was able to pass all tests after that.

1 Like