I have created a script that replicated the examples but it is not passing
here is a link to the files I have
I am not sure what is expected that my solution is not supplying the required output for > 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, where 1 is the service_id
Your code so far
#! /bin/bash
PSQL="psql --username=freecodecamp --dbname=salon -t --no-align -c"
echo -e "\n~~~~~ MY SALON ~~~~~\n"
echo -e "Welcome to My Salon, how can I help you? \n"
# function to list services
SERVICES() {
if [[ $1 ]]
then
echo -e "$1\n"
fi
$PSQL "SELECT * FROM services" | while IFS="|" read ID NAME
do
echo "$ID) $NAME "
done
}
SERVICES
# get choice
read SERVICE_ID_SELECTED
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36
Challenge Information:
Build a Salon Appointment Scheduler - Build a Salon Appointment Scheduler
camper: /project$ ./salon.sh
~~~~~ MY SALON ~~~~~
Welcome to My Salon, how can I help you?
1) cut
2) color
3) perm
4) style
5) trim
6
I could not find that service. What would you like today?
1) cut
2) color
3) perm
4) style
5) trim
with a valid choice
camper: /project$ ./salon.sh
Welcome to My Salon, how can I help you?
1) cut
2) color
3) perm
4) style
5) trim
3
What's your phone number?
I am seeing that the example is showing the ) character in red, is that a requirement?
I also added a new line before I could not find that service
But the test still fails
camper: /project$ ./salon.sh
~~~~~ MY SALON ~~~~~
Welcome to My Salon, how can I help you?
1) cut
2) color
3) perm
4) style
5) trim
9
I could not find that service. What would you like today?
1) cut
2) color
3) perm
4) style
5) trim
#! /bin/bash
PSQL="psql --username=freecodecamp --dbname=salon -t --no-align -c"
echo -e "\n~~~~~ MY SALON ~~~~~\n"
echo -e "Welcome to My Salon, how can I help you?\n"
# function to list services
SERVICES() {
if [[ $1 ]]
then
echo -e "\n$1"
fi
$PSQL "SELECT * FROM services" | while IFS="|" read ID NAME
do
echo -e "$ID\033[38;5;124m)\033[0m $NAME"
done
}
SERVICES
# get choice
read SERVICE_ID_SELECTED
----------------------
camper: /project$ ./salon.sh
~~~~~ MY SALON ~~~~~
Welcome to My Salon, how can I help you?
1) cut
2) color
3) perm
4) style
5) trim
10
I could not find that service. What would you like today?
1) cut
2) color
3) perm
4) style
5) trim
#! /bin/bash
PSQL="psql --username=freecodecamp --dbname=salon -t --no-align -c"
echo -e "\n~~~~~ MY SALON ~~~~~\n"
echo -e "Welcome to My Salon, how can I help you?\n"
# function to list services
SERVICES() {
if [[ $1 ]]
then
echo -e "\n$1"
fi
$PSQL "SELECT * FROM services" | while IFS="|" read ID NAME
do
echo -e "$ID\033[38;5;124m)\033[0m $NAME"
done
}
SERVICES
# get choice
read SERVICE_ID_SELECTED
# schedule appointment
CHOICE=$($PSQL "SELECT service_id FROM services WHERE service_id = $SERVICE_ID_SELECTED")
# make sure choice is valid
while [[ -z $CHOICE ]]
do
SERVICES "I could not find that service. What would you like today?"
read SERVICE_ID_SELECTED
CHOICE=$($PSQL "SELECT service_id FROM services WHERE service_id = $SERVICE_ID_SELECTED")
done
# ask for phone number
echo -e "\nWhat's your phone number?"
read CUSTOMER_PHONE
# check format
while ! [[ $CUSTOMER_PHONE =~ ^[0-9]{3}\-[0-9]{3}\-[0-9]{4}$ ]]
do
echo -e "\nPlease use format as this example 555-555-5555\n"
read CUSTOMER_PHONE
done
# see if phone number in customer list
CUSTOMER_ID=$($PSQL "SELECT customer_id FROM customers WHERE phone = '$CUSTOMER_PHONE'")
# if not ask for name
if [[ -z $CUSTOMER_ID ]]
then
echo -e "\nI don't have a record for that phone number, what's your name?"
read CUSTOMER_NAME
# enter phone number and name into customers
INSERT_CUSTOMER_DATA=$($PSQL "INSERT INTO customers (name, phone) VALUES ('$CUSTOMER_NAME', '$CUSTOMER_PHONE')")
CUSTOMER_ID=$($PSQL "SELECT customer_id FROM customers WHERE phone = '$CUSTOMER_PHONE'")
fi
# find service name
CUSTOMER_NAME=$($PSQL "SELECT name FROM customers WHERE phone = '$CUSTOMER_PHONE'")
SERVICE=$($PSQL "SELECT name FROM services WHERE service_id = $SERVICE_ID_SELECTED")
# ask for appointment time
echo -e "\nWhat time would you like your $SERVICE, $CUSTOMER_NAME?"
read SERVICE_TIME
# enter info into appointments
INSERT_APPOINTMENT_INFO=$($PSQL "INSERT INTO appointments (customer_id, service_id, time) VALUES ($CUSTOMER_ID, $CHOICE, '$SERVICE_TIME')")
# return correct feed back to
echo -e "\nI have put you down for a $SERVICE at $SERVICE_TIME, $CUSTOMER_NAME."
You are correct, that is not required.
The directions include this line though so…
Be sure to get creative, and have fun!
I figured that if the output was correct was what mattered, but I can rip that out. I really don’t think that is the trouble because the tests are failing before it gets to that part of the code, but I will look at things tomorrow and see about removing that input validation.
the problem is, we don’t know what is failing. You can try to check the OUTPUT tab and see what is being reported in the CodeRoad(Tests) and CodeRoad(logs) areas to see if there is anything interesting there.
Having additional checks I would say can stop the test from running (like what if the maintainers didn’t provide a valid telephone according to your check? Then it would fail)
Ok, the validation I was doing on phone number format was the problem. I expect because of test info did not work with validation or as suggested, it made the script take too long to run.
I also specifically called service_id, name in line 12 instead of using * though this alone did not fix the problem and may not have been an issue.