Tell us what’s happening:
My script hits every single requirement that CodeRoad asks for, but it’s not passing any of the tests. My database is fine and the script updates the database properly but I still can’t pass the script-specific tests.
Your code so far
#!/bin/bash
PSQL="psql -X --username=freecodecamp --dbname=salon --tuples-only -c"
echo -e "\n~~ HAIR SALON ~~\n"
MAIN_MENU() {
if [[ $1 ]]
then
echo -e "\n$1"
fi
LIST_SERVICES=$($PSQL "SELECT service_id, name FROM services;")
echo "Services we offer:"
echo "$LIST_SERVICES" | while read SERVICE_ID BAR NAME
do
echo "$SERVICE_ID) $NAME"
done
echo -e "What would you like to do?\n"
echo -e "1) Schedule an appointment\n2) Exit"
read MAIN_MENU_CHOICE
# menu functionality
case $MAIN_MENU_CHOICE in
1) SCHEDULING_MENU ;;
2) EXIT ;;
*) MAIN_MENU "Please enter a valid number." ;;
esac
}
SCHEDULING_MENU() {
if [[ $1 ]]
then
echo -e "\n$1"
fi
# printing the menu again
echo -e "\nWhat service would you like?"
SERVICES=$($PSQL "SELECT service_id, name FROM services;")
echo "Services we offer:"
echo "$SERVICES" | while read SERVICE_ID BAR NAME
do
echo "$SERVICE_ID) $NAME"
done
read SERVICE_ID_SELECTED
# if input is not a number
if [[ ! $SERVICE_ID_SELECTED =~ ^[0-9]+$ ]]
then
# return to menu
SCHEDULING_MENU "Please choose a valid service number."
else
# customer info
echo -e "\nPlease enter your phone number."
read CUSTOMER_PHONE
CUSTOMER_NAME=$($PSQL "SELECT name FROM customers WHERE phone='$CUSTOMER_PHONE'")
if [[ -z $CUSTOMER_NAME ]]
then
# register customer
echo What is your name?
read CUSTOMER_NAME
INSERT_CUSTOMER_RESULT=$($PSQL "INSERT INTO customers(name, phone) VALUES('$CUSTOMER_NAME', '$CUSTOMER_PHONE')")
else
echo Welcome back, $CUSTOMER_NAME.
fi
# customer_id
CUSTOMER_ID=$($PSQL "SELECT customer_id FROM customers WHERE phone='$CUSTOMER_PHONE'")
# make appointment
echo What time would you want your appointment to be?
read SERVICE_TIME
INSERT_APPT_RESULT=$($PSQL "INSERT INTO appointments(customer_id, service_id, time) VALUES($CUSTOMER_ID, $SERVICE_ID_SELECTED, '$TIME')")
SERVICE_NAME=$($PSQL "SELECT name FROM services WHERE service_id=$SERVICE_ID_SELECTED")
# return to main
MAIN_MENU "I have put you down for a $SERVICE_NAME at $SERVICE_TIME, $CUSTOMER_NAME."
fi
}
EXIT() {
echo this is an exit message
}
MAIN_MENU
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:139.0) Gecko/20100101 Firefox/139.0
Challenge Information:
Salon Appointment Scheduler - Build a Salon Appointment Scheduler