The only condition left, Everything looks to be working from my end, I can’t figure out why the test doesn’t pass. here is the result of the run as well.


are you counting all the guesses? Even the bad ones?
I just added a column named best game to the table and queried the data from there. the test for when he wins has already passed
PSQL="psql --username=freecodecamp --dbname=number_guess -t --no-align -c"
SECRET_NUMBER=$((RANDOM % 100 + 1))
echo "$SECRET_NUMBER"
echo "Enter your username:"
read USERNAME
USERNAME_RESULT=$($PSQL "SELECT name FROM names WHERE name='$USERNAME'")
if [[ -z $USERNAME_RESULT ]]
then
echo "Welcome, $USERNAME! It looks like this is your first time here."
else
GAMES_PLAYED=$($PSQL "SELECT games_played FROM names WHERE name='$USERNAME'")
BEST_GAME=$($PSQL "SELECT best_game FROM names WHERE name='$USERNAME'")
*echo "Welcome back, $USERNAME! You have played $GAMES_PLAYED games, and your best game took $BEST_GAME guesses."*
fi
Here’s the part of the script responsible for that condition, i don’t know if i’m missing something
I corrected this btw, i added a 0 ![]()
what’s the logic for figuring out the best game?
I thought i just had to query it from the database hihi, i didn’t even input the result of the games into the database ! but it makes sense, i should put all the results in the database right ? and the pick the best game & display it ?
let me try that real quick
and increment the games played
well I’ve seen people do it that way (input all the results and pick the best)
Not sure if that is needed though. It’s up to you.
From the looks of it it’s not needed, it’s not specified in the user story ! but i’ll give it a try and let you know, thought i was done with this certification
Gotta love the databases héhé
I tried that and still the same problem, i incremented games_played, and replaced the old best_game with the number of tries if the number of tries is <= best_game, still doesn’t want to pass ![]()
Try to compare your output with a diff command to the example output file. Sometimes the test can fail because of a typo.
I solved it, it was not a typo, I added the new username to the data base with an initial number of games played =0 and a best game equal to the biggest integer possible ie : 2147483647, and then after each win, compared the tries to best game, if the tries are less i insert the tries and and increment games played, if not i only increment games played … worked like a charm ![]()
It was not specified in the user stories but the databases had to follow, thanks again for your help @hbar1st !
Databases

