Build a Salon Appointment Scheduler - Build a Salon Appointment Scheduler

Tell us what’s happening:

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

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-salon-appointment-scheduler/5f87ac112ae598023a42df1a.md at main · freeCodeCamp/freeCodeCamp · GitHub

Hi @Dennis-Petre

Try removing the whitespace at the end.

Happy coding

I had added that in an attempt to pass the test and sadly removing it doesn’t help.

Thanks for the suggestion though.

Please run your script, select an option, then post the terminal output.

with an invalid option


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

Updated script followed by out put

#! /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

please post the full code somewhere. Above it looks like just a snippet was posted.

#! /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."

Also see git repository in original post

Hi @Dennis-Petre

What does this do?

Happy coding

That makes the ) character red while creating the required numbered list

I guess I should take some of that out as it is not helping

You don’t need to change the colour.

OK I will remove that

That line now reads

echo -e “$ID) $NAME”

is this part of the requirements? I can’t recall.
I would remove all code that is not strictly requested.

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)

The tests run for a certain amount of time.

If you add something extra, then time could run out before all the tests complete.

Thanks both of you for that valuable feed back. I will rework things and follow up with what I find.

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.

Thanks again for your assistance