Tell us what’s happening:
The final criteria to satisfy is ‘‘You should finish your project while on the main branch, your working tree should be clean, and you should not have any uncommitted changes’’, but I am on the master branch and there is nothing to commit and the tree is clean. Is there some update causing the inconsistency?
camper: /number_guessing_game$ git checkout main
error: pathspec ‘main’ did not match any file(s) known to git
camper: /number_guessing_game$ git status
On branch master
nothing to commit, working tree clean
camper: /number_guessing_game$ git rebase -i HEAD~10
[detached HEAD 6f719ca] chore: Temporary commit before rebase
Date: Fri Jan 17 19:54:06 2025 +0000
1 file changed, 5 insertions(+), 2 deletions(-)
Successfully rebased and updated refs/heads/master.
camper: /number_guessing_game$ git status
On branch master
nothing to commit, working tree clean
camper: /number_guessing_game$ git log --oneline
6f719ca (HEAD → master) chore: Temporary commit before rebase
2d27215 chore: Initial commit
55290ca feat: Corrected string prompting an integer input
e38abc7 fix: Corrected code with the correct database name
407e09f test: tested code without the correct database name
a46162b fix: corrected PQSL for correct prompting, corrected best_game gess count
e81b533 refactor: Code added to prompt user after eaxh guess to strive to wards the random number
c56032a refactor: Code added to prompt user to guess the number between 1 and 1000
42bb9b6 refactor: Code added to find out whether the user is new
8c75f54 refactor: Code added to prompt user for thier name
14e25f5 Initial commit
camper: /number_guessing_game$ git checkout master
Already on ‘master’
camper: /number_guessing_game$ git status
On branch master
nothing to commit, working tree clean
Your code so far
#!/bin/bash
PSQL=“psql --username=freecodecamp --dbname=number_guess -t --no-align -c”
echo “Enter your username:”
read NAME
if [ ${#NAME} -gt 22 ]
then
echo “Database allows for usernames that are 22 characters”
else
USERNAME=$($PSQL “SELECT username FROM user_games WHERE username = ‘$NAME’”)
if [[ -z $USERNAME ]]
then
echo "Welcome, $NAME! It looks like this is your first time here."
INSERT=$($PSQL "insert into user_games (username, games_played, best_game) values ('$NAME', 0, 0)")
games_played=0
best_game=0
else
games_played=$($PSQL "SELECT games_played FROM user_games WHERE username = '$NAME'")
best_game=$($PSQL "SELECT best_game FROM user_games WHERE username = '$NAME'")
echo "Welcome back, $NAME! You have played $games_played games, and your best game took $best_game guesses."
fi
fi
RANDOM_ANS=$(( $RANDOM % 1000 + 1 ))
echo “Guess the secret number between 1 and 1000:”
GUESS=0
while read INPUT
do
if [[ $INPUT =~ [1]+$ ]]
then
GUESS=$((GUESS+1))
if [ $INPUT -eq $RANDOM_ANS ]
then
games_played=$((games_played+1))
echo “You guessed it in $GUESS tries. The secret number was $RANDOM_ANS. Nice job!”
if [[ $best_game -eq 0 || $GUESS -lt $best_game ]]
then
UPDATE=$($PSQL "UPDATE user_games SET best_game=$GUESS, games_played=$games_played WHERE username = '$NAME'")
else
UPDATE=$($PSQL "UPDATE user_games SET games_played=$games_played WHERE username = '$NAME'")
fi
break
else
if [ $INPUT -lt $RANDOM_ANS ]
then
echo "It's higher than that, guess again:"
elif [ $INPUT -gt $RANDOM_ANS ]
then
echo "It's lower than that, guess again:"
fi
fi
else
echo “That is not an integer, guess again:”
fi
done
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Challenge Information:
Number Guessing Game - Build a Number Guessing Game
0-9 ↩︎