Tell us what’s happening:
Describe your issue in detail here.
I’m not sure why below test cases are not passing
As per below script run, I’ve done what is asked in the test cases
my git branch is clean
I already existed command prompt and restart the code road but still it is not passing those test cases.
Your code so far
#! /bin/bash
PSQL=“psql --username=freecodecamp --dbname=number_guess -t --no-align -c”
echo “Enter your username:”
read USER_NAME
NUMBER_TO_BE_GUESSED=$(( RANDOM % 1000 + 1 ))
CHECK_USER_EXIST=$($PSQL “SELECT user_id FROM users where username=‘$USER_NAME’”)
typeset -i ATTEMPT=1
USER_NUMBER=-1
if [[ -z $CHECK_USER_EXIST ]]
then
INSERT_USER=$($PSQL “INSERT INTO users(username) VALUES(‘$USER_NAME’)”)
echo “Welcome, $USER_NAME! It looks like this is your first time here.”
else
GAME_STATS=$($PSQL “SELECT COUNT(*),min(number_of_tries) FROM games where user_id=$CHECK_USER_EXIST”)
echo “$GAME_STATS” | while IFS=“|” read number_of_games best_score
do
echo Welcome back, $USER_NAME! You have played $number_of_games games, and your best game took $best_score guesses.
done
fi
USER_ID=$($PSQL “SELECT user_id FROM users where username=‘$USER_NAME’”)
echo “Guess the secret number between 1 and 1000:”
read USER_NUMBER
while (( NUMBER_TO_BE_GUESSED != USER_NUMBER ))
do
#echo “attempt: $ATTEMPT”
#echo $NUMBER_TO_BE_GUESSED,$USER_NUMBER
if [[ $NUMBER_TO_BE_GUESSED -gt $USER_NUMBER ]]
then
read -p “It’s higher than that, guess again:” USER_NUMBER
else
read -p “It’s lower than that, guess again:” USER_NUMBER
fi
ATTEMPT=ATTEMPT+1
done
INSERT_GAME=$($PSQL “INSERT INTO games(user_id,number_of_tries) VALUES($USER_ID,$ATTEMPT)”)
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36
Challenge: Build a Number Guessing Game
Link to the challenge: