Sorry, I’m not sure what you need.
Can you please show me the statements that caused your headache ![]()
From what I understand and what I remember when I did this project, you should have 2 columns of type INT, no matter what table they are in.
Sorry, I’m not sure what you need.
Can you please show me the statements that caused your headache ![]()
From what I understand and what I remember when I did this project, you should have 2 columns of type INT, no matter what table they are in.
I apologize for not being more clear! and I think your answer was clear to me. I wasn’t sure if I needed to have 2 columns of data type INT in each of my tables for statements like that. but I don’t think that’s the case now. thank you!
Hello Community,
Has anyone finished the number guessing game project from RDB curriculum? They can please help me with the problem below. I am not sure why one of my tests is failing
Below is the code and otput as expected by the user story, still test failes duw to some reason
#! /bin/bash
PSQL="psql -X --username=freecodecamp --dbname=number_game --tuples-only -c"
NUMBER=$(( $RANDOM%1000 ))
echo "Enter your username:"
read USER_NAME
# query the database for given username
USER_NAME_PRESENT_RESULT=$($PSQL "select games_played,best_game FROM users WHERE user_name='$USER_NAME'")
# if userame is not present in database
if [[ -z $USER_NAME_PRESENT_RESULT ]]
then
echo "Welcome, $USER_NAME! It looks like this is your first time here."
# if the username is present in database
else
echo $USER_NAME_PRESENT_RESULT | while read GAMES BAR BEST
do
echo "Welcome back, $USER_NAME! You have played $GAMES games, and your best game took $BEST guesses."
done
fi
Output: (there is one record in the database under the username ‘Raj’)
If this is a problem faced by everyone and needs some fixing, I would be more than happy to contribute - may be @moT01 or any other maintainer can guide me to do so.
I checked my code and the first thing I noticed is that I put an “\n” at the beginning and end of both sentences. Try this and let me know.
Tried this, still test does not pass
Hey @rajpansuriya40,
Perhaps the users stores and instructions aren’t clear enough. You’re supposed to make a loop for users to guess the number. After it prints either the “Welcome …” or “Welcome back, …” line, it should print “Guess the secret number between 1 and 1000:”. Then a user should guess a number, and if it’s wrong, print “It’s higher…” or “It’s lower…”. If it’s not an integer, print “That is not an integer…”. Once they guess it, print “You guessed it in X tries…”. The username, games_played, and best game should get stored in the database.
The tests rely on the user info getting stored in the database via your script. So if it’s a first time user, the name would get stored. Then on the second test, that user name gets used again, where the script should print the “welcome back…” line. Since the username isn’t getting stored, the test doesn’t see that line printed.
Hopefully, that clears some of it up. I’ll see if I can clear some of that up in the instructions or something.
Hey @moT01 ,
Thaks for the response. Though I think that this individual test should have passed irrespective of the further loop and script, but I will try and complete the full script and then again check for the test. This might be the case where some tests only pass when a particular section of the script is completed as we have encountered such situations in previous RDB tutorials. Or it might be like you said, “The tests rely on data stored in database via the script”. So I shall give it one more try and complete the full script before running the tests.
Thanks agaian!
I lost my courses.csv and students.csv files while working on student database 1 aftre resetting is there any way to recover them?
Hi @moT01 I completed the world cup database course and got the expected output but the Code Road checker isn’t marking the last query.
Can you help me in pointing out where I may have missed something? Thanks a lot!
Your “Average number of goals in all games from both teams:” query has some extra zero’s on the end @kayomotunde. That’s probably why it’s not passing. I would take a look at that query and try to get rid of those zero’s. I feel like your query is probably correct though, SQL just added some extra zero’s for some reason. Perhaps your using a different version of Postgres than what was used when creating the project or something - I’m not sure.
Let us know if you can’t get it to pass - or if you do pass it, what you did different.
You can copy them from here @dhairya221b. Here’s the raw courses.csv, and the raw students.csv.
I’ll take a look and see if there’s an issue with the reset command that caused it to not work for you.
Thank you! I got it to pass by using a different query for getting the “Average number of goals in all games from both teams:”. Initially, i had calculated the averages of both winners and opponents individually using the AVG aggregate function but now, I used the same query for “Total number of goals in all games from both teams combined:” and divided that by number of games played (multiplied the denominator by a factor so that I’d get a numerical answer).
I’m too stuck at the same Step Can anyone help
this is my code
echo -e "Welcome to My Salon, how can I help you?\n"
#Getting Service Menu
SERVICE_MENU=$($PSQL "Select service_id, name FROM services WHERE service_id >= 1")
echo "$SERVICE_MENU" | while IFS="|" read ID NAME
do
ID=$(echo "$ID" | sed -Er 's/^ *| *$//g')
NAME=$(echo "$NAME" | sed -Er 's/^ *| *$//g')
echo "$ID) $NAME"
done
read SERVICE_ID
You could simply use:
echo "$SERVICE_MENU" | while read ID BAR NAME
do
echo "$ID) $NAME"
done
i’m currently facing the same problem can you help??
Is it like i have to add other functionality to get that test case passed
Never did find out how to pass this one, but perhaps the link below might help?
MAIN_MENU(){
# display argument if exist
if [[ $1 ]]
then
echo -e "\n$1"
fi
# show service menu
echo "$SERVICES" | while read SERVICE_ID BAR SERVICE_NAME
do
echo "$SERVICE_ID) $SERVICE_NAME"
done
read SERVICE_ID_SELECTED
#if input is not INT
if [[ ! $SERVICE_ID_SELECTED =~ ^[0-9]+$ ]]
then
# return to main menu
MAIN_MENU "I could not find that service. What would you like today?"
fi
SERVICE_ID=$($PSQL "SELECT service_id FROM services WHERE service_id =$SERVICE_ID_SELECTED;")
#if the number input not found
if [[ -z $SERVICE_ID ]]
then
# return to main menu
MAIN_MENU "I could not find that service. What would you like today?"
fi
SERVICE_NAME=$($PSQL "SELECT name FROM services WHERE service_id=$SERVICE_ID")
}
I tried many times, and the code seems fulfill all requirements (especially subtask 1.1:16) (passed all other subtask already)
It’s great if anyone can point out the problem
After the user input SERVICE_ID_SELECTED, the code check whether input is a number. If it is a number, the code will check whether the service_id exist in services table. User will be sent back to MAIN_MENU if either condition do not pass
The problem is found. I avoid the code nested inside if statement, but I forget to handle the exit procedure after everything finish. Thanks so much for the support
I am stuck on the display the numbered list task. Rest of the logic is looking good. Can you please suggest how to solve this?
Hi Gaurav,
I think I was unable to pass that as well.
The two ways I tried were as below:
#display services
#old way:
echo "$SERVICES" | while read SERVICE_ID BAR SERVICE_NAME
do
echo "$SERVICE_ID) $SERVICE_NAME"
done
#the double-SED method:
echo "$SERVICES" | sed -E 's/^ *| *$//g' | sed -E 's/ \|/)/g'
For the method using “sed” it may come down to my regex skills being a little too unrefined.
If you choose to go the “sed” route, all I can suggest is a few articles (I should probably read these myself: )