Tell us what’s happening:
I am in the process of completing the project, but am having trouble getting the script to pass the following tests:
-
You should display a numbered list of the services you offer before the first prompt for input, each with the format
#) <service>
. For example,1) cut
, where1
is theservice_id
-
If you pick a service that doesn’t exist, you should be shown the same list of services again
although I believe I did handle this by creating a function called display and then calling that in main menu before asking for the and then reading it, as instructed.
Your code so far
#!/bin/bash
PSQL="psql -X --username=freecodecamp --dbname=salon --tuples-only -c"
echo -e "\n~~~~~ Salon ~~~~~\n"
display() {
AVAILABLE_SERVICES=$($PSQL "SELECT * FROM services ORDER BY service_id")
echo "$AVAILABLE_SERVICES" | while read -r SERVICE_ID BAR NAME
do
echo "$SERVICE_ID) $NAME"
done
}
main_menu() {
display
while true;
do
MAIN_MENU_SELECTION=""
if [[ $1 ]]; then
echo -e "\n$1"
fi
echo "How may I help you?"
read MAIN_MENU_SELECTION
case $MAIN_MENU_SELECTION in
1) style ;;
2) color ;;
3) cut ;;
4) exit && break ;;
*) echo "Please enter a valid option." ;;
esac
done
}
style() {
echo style ok
}
color() {
echo color ok
}
cut() {
echo cut ok
}
exit() {
echo exit ok
}
main_menu
here is my info in the services table:
salon=> select * from services;
service_id | name
------------+-------
1 | style
2 | color
3 | cut
(3 rows)
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Challenge Information:
Salon Appointment Scheduler - Build a Salon Appointment Scheduler