Relational database - build a bike rental shop

Hi, unable to proceed past this step despite adding the comments as instructed. What am I missing?? Do I need to do something else ref. the comment “And set the available column to false for the bike rented.” ?

Thanks,

Lewis

please give more context to the question. Please show the instructions you were attempting at least.

also try to click the Reset button.
Then retry.

and if that doesn’t work, I would copy the code (copy and paste) and show it to us here as well just in case there is something that is not obvious from the screenshot you took that is more obvious when we see the code
(highlight the code, then right-click and choose Copy, then right-click somewhere else like here and click Paste to paste it in)

Hi Hanaa,

Here’s further context to the problem:

image.png

These comments should be added below the insert customer variable:

image.png

Added to the script - exactly as the hint suggests:

image.png

But does not pass the test:

image.png

Regards,

Lewis

I can’t see any of the images you posted.

Can you try to copy and paste instead the actual text or code?

Here you go:

And set the available column to false for the bike rented. Below the end of the if statement that inserts a new customer, add five more comments; get customer_id , insert bike rental , set bike availability to false , get bike info , and send to main menu

    # if customer doesn't exist
    if [[ -z $CUSTOMER_NAME ]]
    then
      # get new customer name
      echo -e "\nWhat's your name?"
      read CUSTOMER_NAME

      # insert new customer
      INSERT_CUSTOMER_RESULT=$($PSQL "INSERT INTO customers(name, phone) VALUES('$CUSTOMER_NAME', '$PHONE_NUMBER')") 
      # get customer_id

      # insert bike rental

      # set bike availability to false

      # get bike info

      # send to main menu

fi
}

This section asks for the above comments to be added to the ‘bike-shop.sh’ script, but doesn’t pass the test.

the coderoad instruction says that you should put the new comments outside the scope of the if [[ -z $CUSTOMER_NAME ]] code
But your comments are within the scope of that if.
Move them below the fi line

    if [[ -z $CUSTOMER_NAME ]]
    then
      # get new customer name
      echo -e "\nWhat's your name?"
      read CUSTOMER_NAME

      # insert new customer
      INSERT_CUSTOMER_RESULT=$($PSQL "INSERT INTO customers(name, phone) VALUES('$CUSTOMER_NAME', '$PHONE_NUMBER')") 
    fi

     # get customer_id

     # insert bike rental

     # set bike availability to false

     # get bike info

     # send to main menu

I have added the comments as suggested outside of the IF statement, but still does not pass the test. “You should correctly add the suggested comments”

Have you changed anything else? I tried the exact same step this morning and it worked for me.
Perhaps try to reset and copy and paste the code in immediately after the fi and above any other code that was there (not overwriting anything).

I have tried adding the comments just about every which way, bu no joy… Here’s the full script, but I don’t think there are any errors elsewhere in the code.

#!/bin/bash

PSQL="psql -X --username=freecodecamp --dbname=bikes --tuples-only -c"

echo -e "\n~~~~~ Bike Rental Shop ~~~~~\n"

MAIN_MENU() {
  if [[ $1 ]]
  then
    echo -e "\n$1"
  fi

  echo "How may I help you?" 
  echo -e "\n1. Rent a bike\n2. Return a bike\n3. Exit"
  read MAIN_MENU_SELECTION

  case $MAIN_MENU_SELECTION in
    1) RENT_MENU ;;
    2) RETURN_MENU ;;
    3) EXIT ;;
    *) MAIN_MENU "Please enter a valid option." ;;
  esac
}

RENT_MENU() {
  # get available bikes
  AVAILABLE_BIKES=$($PSQL "SELECT bike_id, type, size FROM bikes WHERE available = true ORDER BY bike_id")

  # if no bikes available
  if [[ -z $AVAILABLE_BIKES ]]
  then
    # send to main menu
    MAIN_MENU "Sorry, we don't have any bikes available right now."
  else
    # display available bikes
    echo -e "\nHere are the bikes we have available:"
    echo "$AVAILABLE_BIKES" | while read BIKE_ID BAR TYPE BAR SIZE
    do
      echo "$BIKE_ID) $SIZE\" $TYPE Bike"
    done

    # ask for bike to rent
    echo -e "\nWhich one would you like to rent?"
    read BIKE_ID_TO_RENT

    # if input is not a number
    if [[ ! $BIKE_ID_TO_RENT =~ ^[0-9]+$ ]]
    then
      # send to main menu
      MAIN_MENU "That is not a valid bike number."
    else
      # get bike availability
      BIKE_AVAILABILITY=$($PSQL "SELECT available FROM bikes WHERE bike_id = $BIKE_ID_TO_RENT AND available = true")

      # if not available
      if [[ -z $BIKE_AVAILABILITY ]]
      then
        # send to main menu
        MAIN_MENU "That bike is not available."
      else
        # get customer info
        echo -e "\nWhat's your phone number?"
        read PHONE_NUMBER

        CUSTOMER_NAME=$($PSQL "SELECT name FROM customers WHERE phone = '$PHONE_NUMBER'")

        # if customer doesn't exist
        if [[ -z $CUSTOMER_NAME ]]
        then
          # get new customer name
          echo -e "\nWhat's your name?"
          read CUSTOMER_NAME

          # insert new customer
          INSERT_CUSTOMER_RESULT=$($PSQL "INSERT INTO customers(name, phone) VALUES('$CUSTOMER_NAME', '$PHONE_NUMBER')") 
        fi
  # get customer_id

  # insert bike rental

  # set bike availability to false

  # get bike info

  # send to main menu
}

RETURN_MENU() {
  echo "Return Menu"
}

EXIT() {
  echo -e "\nThank you for stopping in.\n"
}

MAIN_MENU

The test is looking for some closing fi after the comments you are missing.

You should be able to just add them, but you could also reset and paste your five comments in the correct spot. Then you would be sure the file looks how it’s supposed to.

I think there’s three if statements that don’t have a fi to go with them. The if [[ -z $BIKE_AVAILABILITY ]], if [[ ! $BIKE_ID_TO_RENT =~ ^[0-9]+$ ]], and if [[ -z $AVAILABLE_BIKES ]]. I think they are all suppose to have a fi after the comments.

Looks like a total of 4 if statements to be closed, but still no dice… :neutral_face:

#!/bin/bash

PSQL="psql -X --username=freecodecamp --dbname=bikes --tuples-only -c"

echo -e "\n~~~~~ Bike Rental Shop ~~~~~\n"

MAIN_MENU() {
  if [[ $1 ]]
  then
    echo -e "\n$1"
  fi

  echo "How may I help you?" 
  echo -e "\n1. Rent a bike\n2. Return a bike\n3. Exit"
  read MAIN_MENU_SELECTION

  case $MAIN_MENU_SELECTION in
    1) RENT_MENU ;;
    2) RETURN_MENU ;;
    3) EXIT ;;
    *) MAIN_MENU "Please enter a valid option." ;;
  esac
}

RENT_MENU() {
  # get available bikes
  AVAILABLE_BIKES=$($PSQL "SELECT bike_id, type, size FROM bikes WHERE available = true ORDER BY bike_id")

  # if no bikes available
  if [[ -z $AVAILABLE_BIKES ]]
  then
    # send to main menu
    MAIN_MENU "Sorry, we don't have any bikes available right now."
  else
    # display available bikes
    echo -e "\nHere are the bikes we have available:"
    echo "$AVAILABLE_BIKES" | while read BIKE_ID BAR TYPE BAR SIZE
    do
      echo "$BIKE_ID) $SIZE\" $TYPE Bike"
    done

    # ask for bike to rent
    echo -e "\nWhich one would you like to rent?"
    read BIKE_ID_TO_RENT

    # if input is not a number
    if [[ ! $BIKE_ID_TO_RENT =~ ^[0-9]+$ ]]
    then
      # send to main menu
      MAIN_MENU "That is not a valid bike number."
    else
      # get bike availability
      BIKE_AVAILABILITY=$($PSQL "SELECT available FROM bikes WHERE bike_id = $BIKE_ID_TO_RENT AND available = true")

      # if not available
      if [[ -z $BIKE_AVAILABILITY ]]
      then
        # send to main menu
        MAIN_MENU "That bike is not available."
      else
        # get customer info
        echo -e "\nWhat's your phone number?"
        read PHONE_NUMBER

        CUSTOMER_NAME=$($PSQL "SELECT name FROM customers WHERE phone = '$PHONE_NUMBER'")

        # if customer doesn't exist
  if [[ -z $CUSTOMER_NAME ]]
  then
    # get new customer name
    echo -e "\nWhat's your name?"
    read CUSTOMER_NAME

    # insert new customer
    INSERT_CUSTOMER_RESULT=$($PSQL "INSERT INTO customers(name, phone) VALUES('$CUSTOMER_NAME', '$PHONE_NUMBER')")
    
      fi
    fi
  fi
fi

  # get customer_id

  # insert bike rental

  # set bike availability to false

  # get bike info

  # send to main menu

}

RETURN_MENU() {
  echo "Return Menu"
}

EXIT() {
  echo -e "\nThank you for stopping in.\n"
}

MAIN_MENU

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

you need to move the comments directly after this block according to the instructions
Below the end of the if statement that inserts a new customer, add five more comments; get customer_id , insert bike rental , set bike availability to false , get bike info , and send to main menu

It’s not working for me too…I have the same problem

Where is my code:

#!/bin/bash

PSQL=“psql -X --username=freecodecamp --dbname=bikes --tuples-only -c”

echo -e “\n~~~~~ Bike Rental Shop ~~~~~\n”

MAIN_MENU() {
if [[ $1 ]]
then
echo -e “\n$1”
fi

echo “How may I help you?”
echo -e “\n1. Rent a bike\n2. Return a bike\n3. Exit”
read MAIN_MENU_SELECTION

case $MAIN_MENU_SELECTION in
1) RENT_MENU ;;
2) RETURN_MENU ;;
3) EXIT ;;
*) MAIN_MENU “Please enter a valid option.” ;;
esac
}

RENT_MENU() {

get available bikes

AVAILABLE_BIKES=$($PSQL “SELECT bike_id, type, size FROM bikes WHERE available = true ORDER BY bike_id”)

if no bikes available

if [[ -z $AVAILABLE_BIKES ]]
then
# send to main menu
MAIN_MENU “Sorry, we don’t have any bikes available right now.”
else
# display available bikes
echo -e “\nHere are the bikes we have available:”
echo “$AVAILABLE_BIKES” | while read BIKE_ID BAR TYPE BAR SIZE
do
echo “$BIKE_ID) $SIZE" $TYPE Bike”
done

# ask for bike to rent
echo -e "\nWhich one would you like to rent?"
read BIKE_ID_TO_RENT

# if input is not a number
if [[ ! $BIKE_ID_TO_RENT =~ ^[0-9]+$ ]]
then
  # send to main menu
  MAIN_MENU "That is not a valid bike number."
else
  # get bike availability
  BIKE_AVAILABILITY=$($PSQL "SELECT available FROM bikes WHERE bike_id = $BIKE_ID_TO_RENT AND available = true")

  # if not available
  if [[ -z $BIKE_AVAILABILITY ]]
  then
    # send to main menu
    MAIN_MENU "That bike is not available."
  else
    # get customer info
    echo -e "\nWhat's your phone number?"
    read PHONE_NUMBER

    CUSTOMER_NAME=$($PSQL "SELECT name FROM customers WHERE phone = '$PHONE_NUMBER'")

    # if customer doesn't exist
    if [[ -z $CUSTOMER_NAME ]]
    then
      # get new customer name
      echo -e "\nWhat's your name?"
      read CUSTOMER_NAME

      # insert new customer
      INSERT_CUSTOMER_RESULT=$($PSQL "INSERT INTO customers(name, phone) VALUES('$CUSTOMER_NAME', '$PHONE_NUMBER')") 
    fi
    
    #get customer_id

    #insert bike rental

    #set bike availability to false

    #get bike info

    #send to main menu
    
  fi
fi

fi
}

RETURN_MENU() {
echo “Return Menu”
}

EXIT() {
echo -e “\nThank you for stopping in.\n”
}

MAIN_MENU

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