Build A Number Guessing Game Project, I can't pass some test, despite having the right output

So I have the bash script for the number guessing game and when testing it outputs everything the tasks ask for, but I still can’t get the tasks passed. I wrote everything from scratch a second time, but still running into the same problems.
When I look at the outputs and compare it with the tasks, I can’t see the difference in text.
I have absolute no idea where to fix it.

I can’t pass following tasks:

  1. 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

  2. Until they guess the secret number, it should print It's lower than that, guess again: if the previous input was higher than the secret number, and It's higher than that, guess again: if the previous input was lower than the secret number. Asking for input each time until they input the secret number.

  3. 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!

I put the bash script and sql (I truncated, before I did the pg_dump) into codesandbox.

Ok somehow, when I run the test multiple time, sometimes the second one passes and sometimes not without changing anything.

These are the outputs from terminal:

codeally@23f2de9b767d:~/project/number_guessing_game$ ./number_guess.sh
Enter your username:
pong
Welcome, pong! It looks like this is your first time here.
Guess the secret number between 1 and 1000:
3
It’s higher than that, guess again:
5
You guessed it in 2 tries. The secret number was 5. Nice job!

codeally@23f2de9b767d:~/project/number_guessing_game$ ./number_guess.sh
Enter your username:
abcd
Welcome, abcd! It looks like this is your first time here.
Guess the secret number between 1 and 1000:
5
It’s lower than that, guess again:
3
You guessed it in 2 tries. The secret number was 3. Nice job!

The random number only goes from 1-10 for testing purposes.

codeally@23f2de9b767d:~/project/number_guessing_game$ ./number_guess.sh
Enter your username:
pong
Welcome back, pong! You have played 1 games, and your best game took 2 guesses.
Guess the secret number between 1 and 1000:
3
It’s higher than that, guess again:
5
It’s lower than that, guess again:
4
You guessed it in 3 tries. The secret number was 4. Nice job!

I’m on the same course and i’m getting an error only for the welcome back part even though the script does exactly what i want it to…I can’t find anything since yesterday…I would advise replacing the operators with -lt, -gt, -eq…
if i find something i will update, if you find anything update please
It’s probably something with the number of guesses

So I managed to solve it, I had to remove spaces, where I thought it wouldn’t be a problem, I also wrote the code in a different style, which ended with more lines of code, but it somehow worked.

1 Like

can you provide code for reference?