"Salon Appointment Scheduler": an incomprehensible error

I’m doing the challenge: “Build a Salon Appointment Scheduler“. The verification system on gitpod tells me that I have solved all the tasks, except one, the last one:

After an appointment is successfully added, you should output the message `I have put you down for a <service> at <time>, <name>`. For example, if the user chooses `cut` as the service, `10:30` is entered for the time, and their name is `Fabio` in the database the output would be `I have put you down for a cut at 10:30, Fabio`. Make sure your script finishes running after completing any of the tasks above, or else the tests won't pass

The error message is: SUBTASKS 1.1 :21 You should see the suggested message after adding a new appointment.

The statement that prints the requested message is:

echo -e "\nI put you down for a $(echo $CHOOSEN_SERVICE_NAME | sed -r 's/^ *| *$//g') to $(echo $SERVICE_TIME | sed -r 's/^ *| *$//g'), $(echo $CUSTOMER_NAME | sed -r 's/^ *| *$//g')"

I report all the code of salon.sh:

#!/bin/bash

# Salon manager

PSQL="psql --username=postgres --dbname=salon -X --tuples-only -c"

echo -e "\n~~~~~ MY SALON ~~~~~\n"

MAIN_MENU() {
  # Show a message if given as a parameter
  if [[ $1 ]]
  then
    echo -e "\n$1"
  fi

  echo -e "Here are the services we offer:\n"
  # Show services
  SERVICES_RESULT=$($PSQL "SELECT service_id, name FROM services")
  echo "$SERVICES_RESULT" | while read SERVICE_ID BAR SERVICE_NAME
  do
    echo "$SERVICE_ID) $SERVICE_NAME"
  done

  echo -e "\nx) Exit"

  # choose a service
  echo -e "\nWhat service do you want to book?"
  read SERVICE_ID_SELECTED

  # if response = x (exit)
  if [[ $SERVICE_ID_SELECTED =~ ^[xX]$ ]]
  then
    exit 0
  fi

  # if service does not exists
  SERVICE_IN_DB=$($PSQL "SELECT service_id FROM services WHERE service_id = $SERVICE_ID_SELECTED;")
  if [[ -z $SERVICE_IN_DB ]]
  then
    # send to main menu
    MAIN_MENU "That service does not exists\n"
  else
    # show the choosen service
    CHOOSEN_SERVICE_NAME=$($PSQL "SELECT name FROM services WHERE service_id = $SERVICE_ID_SELECTED;")
    echo -e "\nYou choosed the service: $(echo $CHOOSEN_SERVICE_NAME | sed -r 's/^ *| *$//g')"
  fi

  # if service exists, ask for a phone number
  echo -e "\nWhat is your phone number?\n"
  read CUSTOMER_PHONE
  # if CUSTOMER_PHONE is not into the db
  CUSTOMER_PHONE_IN_DB=$($PSQL "SELECT phone FROM customers WHERE phone = '$CUSTOMER_PHONE';")
  if [[ -z $CUSTOMER_PHONE_IN_DB ]]
  then
    # ask for the customer name
    echo -e "\nThere is no customer with that number."
    echo "What is your name?"
    read CUSTOMER_NAME
    # insert phone_number and customer name into the db
    INSERT_CUSTOMER_RESULT=$($PSQL "INSERT INTO customers (phone, name) VALUES ('$CUSTOMER_PHONE', '$CUSTOMER_NAME');")
    # get the customer_id now inserted
    CUSTOMER_ID=$($PSQL "SELECT customer_id FROM customers WHERE phone = '$CUSTOMER_PHONE';")
  else
    # retrieve the name and id of the customer, for future use
    CUSTOMER_NAME=$($PSQL "SELECT name FROM customers WHERE phone = '$CUSTOMER_PHONE';")
    CUSTOMER_ID=$($PSQL "SELECT customer_id FROM customers WHERE phone = '$CUSTOMER_PHONE';")
  fi
  # ask for the service time
  echo -e "\nWhat time would you like your $(echo $CHOOSEN_SERVICE_NAME | sed -r 's/^ *| *$//g'), $(echo $CUSTOMER_NAME | sed -r 's/^ *| *$//g')?"
  read SERVICE_TIME
  # insert service_id, customer_id and time into db
  INSERT_APPOINTMENT_RESULT=$($PSQL "INSERT INTO appointments (service_id, customer_id, time) VALUES ($SERVICE_ID_SELECTED, $CUSTOMER_ID, '$SERVICE_TIME');")
  # notify the success of the operation
  echo -e "\nI have put you down for a $(echo $CHOOSEN_SERVICE_NAME | sed -r 's/^ *| *$//g') at $(echo $SERVICE_TIME | sed -r 's/^ *| *$//g'), $(echo $CUSTOMER_NAME | sed -r 's/^ *| *$//g')"
}

MAIN_MENU

Here it is the dump of the database

--
-- PostgreSQL database dump
--

-- Dumped from database version 12.19
-- Dumped by pg_dump version 12.19

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

DROP DATABASE salon;

CREATE DATABASE salon WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'C' LC_CTYPE = 'C';


ALTER DATABASE salon OWNER TO freecodecamp;

\connect salon

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

SET default_tablespace = '';

SET default_table_access_method = heap;

CREATE TABLE public.appointments (
    appointment_id integer NOT NULL,
    service_id integer NOT NULL,
    customer_id integer NOT NULL,
    "time" character varying(15)
);


ALTER TABLE public.appointments OWNER TO freecodecamp;

CREATE SEQUENCE public.appointments_appointment_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.appointments_appointment_id_seq OWNER TO freecodecamp;

ALTER SEQUENCE public.appointments_appointment_id_seq OWNED BY public.appointments.appointment_id;

CREATE TABLE public.customers (
    customer_id integer NOT NULL,
    phone character varying(15),
    name character varying(50)
);


ALTER TABLE public.customers OWNER TO freecodecamp;

CREATE SEQUENCE public.customers_customer_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.customers_customer_id_seq OWNER TO freecodecamp;

ALTER SEQUENCE public.customers_customer_id_seq OWNED BY public.customers.customer_id;

CREATE TABLE public.services (
    service_id integer NOT NULL,
    name character varying(50)
);


ALTER TABLE public.services OWNER TO freecodecamp;

CREATE SEQUENCE public.services_service_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.services_service_id_seq OWNER TO freecodecamp;

ALTER SEQUENCE public.services_service_id_seq OWNED BY public.services.service_id;

ALTER TABLE ONLY public.appointments ALTER COLUMN appointment_id SET DEFAULT nextval('public.appointments_appointment_id_seq'::regclass);

ALTER TABLE ONLY public.customers ALTER COLUMN customer_id SET DEFAULT nextval('public.customers_customer_id_seq'::regclass);

ALTER TABLE ONLY public.services ALTER COLUMN service_id SET DEFAULT nextval('public.services_service_id_seq'::regclass);

INSERT INTO public.appointments VALUES (3, 1, 8, '10:30');
INSERT INTO public.appointments VALUES (4, 2, 8, '11am');

INSERT INTO public.customers VALUES (8, '555-555-5555', 'Fabio');

INSERT INTO public.services VALUES (1, 'Hair cut');
INSERT INTO public.services VALUES (2, 'Nails color');
INSERT INTO public.services VALUES (3, 'Barbering');
INSERT INTO public.services VALUES (4, 'Eyebrows styling');
INSERT INTO public.services VALUES (5, 'Pierce shine');

SELECT pg_catalog.setval('public.appointments_appointment_id_seq', 4, true);

SELECT pg_catalog.setval('public.customers_customer_id_seq', 8, true);

SELECT pg_catalog.setval('public.services_service_id_seq', 5, true);

ALTER TABLE ONLY public.appointments
    ADD CONSTRAINT appointments_pkey PRIMARY KEY (appointment_id);

ALTER TABLE ONLY public.customers
    ADD CONSTRAINT customers_phone_key UNIQUE (phone);

ALTER TABLE ONLY public.customers
    ADD CONSTRAINT customers_pkey PRIMARY KEY (customer_id);

ALTER TABLE ONLY public.services
    ADD CONSTRAINT services_pkey PRIMARY KEY (service_id);

ALTER TABLE ONLY public.appointments
    ADD CONSTRAINT appointments_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES public.customers(customer_id);

ALTER TABLE ONLY public.appointments
    ADD CONSTRAINT appointments_service_id_fkey FOREIGN KEY (service_id) REFERENCES public.services(service_id);
--
-- PostgreSQL database dump complete
--

In all the tests I have done the results seem to be those requested by the challenge:

I have put you down for a Nails color at 11am, Fabio

I can’t understand what could be wrong.

Any help will be appreciated.

Thank you

can you try changing it to
I have put you down

instead of
I put you down?

Nevermind, I see you already have ‘have’ there.

can you also try changing these to one word only in case the test is sensitive? (I can’t recall how to find the code for these tests on github to check)

Hello @hbar1st , thank you for answer.

Well, I made the following corrections:

  1. in salon.sql: the services now are the ones I list
INSERT INTO public.services VALUES (1, 'cut');
INSERT INTO public.services VALUES (2, 'nails');
INSERT INTO public.services VALUES (3, 'barbering');
INSERT INTO public.services VALUES (4, 'eyebrows');
INSERT INTO public.services VALUES (5, 'piercing');
  1. in salon.sh: I added an exit statement to the end of MAIN_MENU to ensure the correct exit from the program.

I started a new gitpod to test the corrections: no difference from the point of view of the result: the system continues to give me the same error message in the same place: SUBTASKS 1.1 :21 You should display the suggested message after adding a new appointment

There’s one little detail different in that result, missing dot at the end.

1 Like

Yes you are right. I thank you.