# Number Guessing Game - Build a Number Guessing Game

Tell us what’s happening:
Tried in some different ways to finish this challenge, but couldn’t. Only one test’s not passing, can someone give me a tip or smth? Saw some others that were having the same issue so wanted to have a lead of it, any thoughts?

Your code so far

#!/bin/bash

PSQL=“psql --username=freecodecamp --dbname=number_guess -t --no-align -c”
SECRETNUMBER=\$(( RANDOM % 1000 + 1 ))
GLOBAL_NUMBER_GUESSES=0

GUESS_NUMBER() {
NUMBER_GUESSES=0
echo -e “\nGuess the secret number between 1 and 1000:”
(( NUMBER_GUESSES++ ))

while ! [[ \$USER_GUESS =~ [1]+\$ ]]
do
echo “That is not an integer, guess again:”
done

while [[ \$USER_GUESS -ne \$SECRETNUMBER ]]
do
if [[ \$USER_GUESS -gt \$SECRETNUMBER ]]
then
echo -e “\nIt’s lower than that, guess again:”
else
echo -e “\nIt’s higher than that, guess again:”
fi
(( NUMBER_GUESSES++ ))
done

echo -e “\nYou guessed it in \$NUMBER_GUESSES tries. The secret number was \$SECRETNUMBER. Nice job!”
GLOBAL_NUMBER_GUESSES=\$NUMBER_GUESSES
exit
}

if [[ -z \$USERNAME ]]
then
echo -e “\nWelcome, \$INPUT_USERNAME! It looks like this is your first time here.”
GUESS_NUMBER

\$PSQL “INSERT INTO users(username, games_played, best_game) VALUES(‘\$INPUT_USERNAME’, 1, \$GLOBAL_NUMBER_GUESSES)”
else
BEST_GAME=\$(\$PSQL “SELECT best_game FROM users WHERE user_id = ‘\$USERNAME_ID’”)
GAMES_PLAYED=\$(\$PSQL “SELECT games_played FROM users WHERE user_id = ‘\$USERNAME_ID’”)

echo -e “\nWelcome back, \$USERNAME! You have played \$GAMES_PLAYED games, and your best game took \$BEST_GAME guesses.”
GUESS_NUMBER
(( GAMES_PLAYED++ ))

if [[ \$GLOBAL_NUMBER_GUESSES -lt \$BEST_GAME ]]
then
\$PSQL “UPDATE users SET games_played = \$GAMES_PLAYED, best_game = \$GLOBAL_NUMBER_GUESSES WHERE user_id = ‘\$USERNAME_ID’”
else
\$PSQL “UPDATE users SET games_played = \$GAMES_PLAYED, best_game = \$BEST_GAME WHERE user_id = ‘\$USERNAME_ID’”
fi
fi

User Agent is: `Chrome 114.0.5735.199`
• 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