I cannot get the step below. I reset the step a few times. I refresh the browser page a few times. Nothing worked. Does anyone know why?
step in coderoad
And set the available
column to false for the bike rented. Below the end of the if
statement that inserts a new customer, add five more comments; get customer_id
, insert bike rental
, set bike availability to false
, get bike info
, and send to main menu
I repeated this step multiple times over multiple days. I had restarted from the beginning already. I reset this step multiple times also. I keep getting the same error that it said something to the effect of “you should correctly add the suggested comment.” I cannot get past this step. Could somebody please help?
From coderoad
And set the available
column to false for the bike rented. Below the end of the if
statement that inserts a new customer, add five more comments; get customer_id
, insert bike rental
, set bike availability to false
, get bike info
, and send to main menu
#!/bin/bash
PSQL="psql -X --username=freecodecamp --dbname=bikes --tuples-only -c"
echo -e "\n~~~~~ Bike Rental Shop ~~~~~\n"
MAIN_MENU() {
if [[ $1 ]]
then
echo -e "\n$1"
fi
echo "How may I help you?"
echo -e "\n1. Rent a bike\n2. Return a bike\n3. Exit"
read MAIN_MENU_SELECTION
case $MAIN_MENU_SELECTION in
1) RENT_MENU ;;
2) RETURN_MENU ;;
3) EXIT ;;
*) MAIN_MENU "Please enter a valid option." ;;
esac
}
RENT_MENU() {
# get available bikes
AVAILABLE_BIKES=$($PSQL "SELECT bike_id, type, size FROM bikes WHERE available = true ORDER BY bike_id")
# if no bikes available
if [[ -z $AVAILABLE_BIKES ]]
then
# send to main menu
MAIN_MENU "Sorry, we don't have any bikes available right now."
else
# display available bikes
echo -e "\nHere are the bikes we have available:"
echo "$AVAILABLE_BIKES" | while read BIKE_ID BAR TYPE BAR SIZE
do
echo "$BIKE_ID) $SIZE\" $TYPE Bike"
done
# ask for bike to rent
echo -e "\nWhich one would you like to rent?"
read BIKE_ID_TO_RENT
# if input is not a number
if [[ ! $BIKE_ID_TO_RENT =~ ^[0-9]+$ ]]
then
# send to main menu
MAIN_MENU "That is not a valid bike number."
else
# get bike availability
BIKE_AVAILABILITY=$($PSQL "SELECT available FROM bikes WHERE bike_id = $BIKE_ID_TO_RENT AND available = true")
# if not available
if [[ -z $BIKE_AVAILABILITY ]]
then
# send to main menu
MAIN_MENU "That bike is not available."
else
# get customer info
echo -e "\nWhat's your phone number?"
read PHONE_NUMBER
CUSTOMER_NAME=$($PSQL "SELECT name FROM customers WHERE phone = '$PHONE_NUMBER'")
# if customer doesn't exist
if [[ -z $CUSTOMER_NAME ]]
then
# get new customer name
echo -e "\nWhat's your name?"
read CUSTOMER_NAME
# insert new customer
INSERT_CUSTOMER_RESULT=$($PSQL "INSERT INTO customers(name, phone) VALUES('$CUSTOMER_NAME', '$PHONE_NUMBER')")
fi
#get customer_id
#insert bike rental
#set bike availability to false
#get bike info
#send to main menu
fi
fi
fi
}
RETURN_MENU() {
echo "Return Menu"
}
EXIT() {
echo -e "\nThank you for stopping in.\n"
}
MAIN_MENU
You’re stuck on the step which asks you just to add those comments?
There’s a number of things which could be causing this test not to pass.
The code itself is fine, though sometimes if you format the code slightly differently it helps the code to pass the tests.
Try adding an extra blank line before the first comment and/or a space after the hash in each comment.
Also try the reset button on the CodeRoad window (next to the Run button). Then hit Run again.
It’s slightly frustrating but usually with a bit of fiddling, I’ve managed to get the tests to pass in the end.
I 've used the reset button next to the CodeRoad window a bunch of times, but that does not work. Ok so reading your comment. I added extra space between the # and the text and that work now. This one is especially the pain in the butt. Thank you for the response.
The testing on these courses can be temperamental at times… which is annoying! I’ve always managed to get around them in the end though, so be persistent and try many different things if you get stuck with code that you know is definitely correct…
I appreciate your response because sometimes when I am frustrated I can’t think of these annoying things. When you mention them, it’s like oh, I should thought of that.