Salon Appointment Scheduler - Build a Salon Appointment Scheduler

Tell us what’s happening:

The test “If you pick a service that doesn’t exist, you should be shown the same list of services again” is not passing even though it is working as expected when running manually.

I’ve been stuck on this for quite some time now. Any input would be much appreciated.

Thank You!

Your code so far

#!/bin/bash
PSQL="psql --username=freecodecamp --dbname=salon --no-align --tuples-only -c"

echo -e "\n~~~~~ MY SALON ~~~~~"
echo -e "\nWelcome, how can I help you today?"

MAIN_MENU() {
  if [[ $1 ]] 
  then
   echo $1
  fi
    
  $PSQL "SELECT service_id, name FROM services ORDER BY service_id" | while IFS="|" read SERVICE_ID  SERVICE_NAME
  do
    echo "$SERVICE_ID) $SERVICE_NAME"
  done
  SERVICE_COUNT=$($PSQL "SELECT COUNT(*) FROM services WHERE service_id IS NOT NULL")
  read SERVICE_ID_SELECTED
  if [[ ! $SERVICE_ID_SELECTED =~ ^[1-$SERVICE_COUNT]$ ]] 
  then
    MAIN_MENU "I could not find that service. What would you like today?"
  else
    SERVICE=$($PSQL "SELECT name FROM services WHERE service_id = $SERVICE_ID_SELECTED")
    echo -e "\nWhat's your phone number?"
    read CUSTOMER_PHONE
  fi
  CUSTOMER_ID=$($PSQL "SELECT customer_id FROM customers WHERE phone = '$CUSTOMER_PHONE'")
  if [[ -z $CUSTOMER_ID ]]
  then
    echo -e "\nI don't have a record for that phone number, what's your name?"
    read CUSTOMER_NAME
    CUSTOMER_RESULT=$($PSQL "INSERT INTO customers (name, phone) VALUES('$CUSTOMER_NAME', '$CUSTOMER_PHONE')")
  fi
  CUSTOMER_ID=$($PSQL "SELECT customer_id FROM customers WHERE phone = '$CUSTOMER_PHONE'")
  CUSTOMER_NAME=$($PSQL "SELECT name FROM customers WHERE phone = '$CUSTOMER_PHONE'")
  if [[ $CUSTOMER_ID ]]
  then
    echo -e "\nWhat time would you like your service, $CUSTOMER_NAME?"
    read SERVICE_TIME
    
    APPOINTMENT_RESULT=$($PSQL "INSERT INTO appointments (service_id, customer_id, time) VALUES ($SERVICE_ID_SELECTED, $CUSTOMER_ID, '$SERVICE_TIME')")
  fi
  echo -e "I have put you down for a $SERVICE at $SERVICE_TIME, $CUSTOMER_NAME."
}

MAIN_MENU

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36

Challenge Information:

Salon Appointment Scheduler - Build a Salon Appointment Scheduler

Every other tests except this one is passing. If there is someone who faced this issue before or someone who knows what the issue here is please let me know.

Thanks

I found the issue. I had to add a return statement after the ‘if condition’ called MAIN_MENU

again , if the service is not available.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.