High there. I am doing the Relational Database Certification, and so far I have done that course without any problems. However in the guided project where a bike rental shop has to be created, I have encountered some trouble. It is with this bit of code:
# if not available
if [[ -z $BIKE_AVAILABILITY ]]
then
# send to main menu
fi
Despite putting this code in the bike-shop.sh file, it does not let me go to the next step. I thought I made a mistake, so I went to the hints, and typed the whole thing again. When it did not let me pass again, I copied and pasted that into the file. It still did not let me pass. Sometimes, I have to click on the “run” option to get passed the current step. I instead got this:
“Your “MAIN_MENU” function should have the correct “if” condition added”
This is confusing, because I am not working in the main menu. I am working in the RENT_MENU function instead. I have decided to provide the whole script below. The top of the script also contains the same message as a comment.
# Your "MAIN_MENU" function should have the correct "if" condition added
#!/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")
echo "$BIKE_AVAILABILITY"
# if not available
if [[ -z $BIKE_AVAILABILITY ]]
then
# send to main menu
fi
# send to main menu
fi
# send to main menu
fi
# send to main menu
}
RETURN_MENU(){
echo "Return Menu"
}
EXIT(){
echo -e "\nThank you for stopping in.\n"
}
MAIN_MENU
I have formatted this in a hurry using VSCode. I am not certain how it looks, as I am blind. I was doing this in notepad originally; Because I find it easier to manage. (That doesn’t mean I don’t use VSCode. I love that editor actually.)
Please provide help regarding this. I want to be done with this project, it has been delayed quite a bit already.
On a final note, this is my first time posting to this forum. If I am posting this on a wrong place, please forgive me. It is not my intention to cause any trouble.