Learn-bash-and-sql-by-building-a-bike-rental-shop

Hello! I’ve got a problem. The site doesn’t accept my code. I tried to change it, and followed the instructions, but couldn’t solve it. Here are the instructions

#!/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")
  echo "$AVAILABLE_BIKES"

  # 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"

    # ask for bike to rent

    # if input is not a number

    # send to main menu

  fi
}

RETURN_MENU() {
  echo "Return Menu"
}

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

MAIN_MENU

Thank you, I really appreciate your reply!

Hi there, what troubleshooting steps have you tried? (Eg have you tried to reset the ste? Any others?)

I reset few times, used different browsers (Google Chrome, Mozilla, Microsoft Edge).

I also cleaned the browser cash and tried a soft reset on the site.

I think you should move echo $AVAILABLE_BIKES from #get_available_bikes to #display_available bikes…The command should only be below #display_available_bikes…Have you tried that?

Here is something you have not tried yet:

Erase the line added.
Close the file.
Reset the step.
Open the file.
Add the line.

If the above doesn’t work, then try

Reset the step
Exit the whole project in the browser
Go to a different project in fCC and open it
Exit that one
Go to the bike project and open it
Retry the step

Yes, you are right. The solution is - remove the line from get_available_bikes to display_available_bikes. Many thanks!

just to clarify, the issue was that instead of moving the line, you had copied it only to the new location.
(once you deleted the old line, you were able to pass this?)

Yes, the problem is that I didn’t remove the line :grin:

1 Like