Im stuck on the 5 workshops bash scripting workshop. I can't figure out what I've done wrong with the code so anyone who has done it, can you help me out? Its for the fortune.sh file

#!/bin/bash

# Program to tell a person’s fortune

echo -e “\n~~ Fortune Teller ~~\n”

RESPONSES=(“Yes” “No” “Maybe” “Outlook good” “Don’t count on it” “Ask again later”)

N=$(( $RANDOM % 6 ))

GET_FORTUNE() {

if [[ ! $1 ]]

then

echo "Ask a yes or no question:"

else

echo "Try again. Make sure it ends with a question mark:"

fi

read QUESTION

}

GET_FORTUNE

until [[ QUESTION =\~ \\? ]]

do

GET_FORTUNE again

done

echo ${RESPONSES[$N]}

Not sure why the until question part is two seperate lines, its one in my file! I have also removed the quotations marks around the ‘then’ and ‘else’.

it would help to post a link to the course in fcc so someone who did it in the past (like me), can quickly find it again to begin with.

Could you format your code by putting the three backticks at the start and end of the code - and remove the backticks in the middle probably? Make sure the posted code matches what you have.

Also, can you share the instructions for the step you are on?

There are two ways you can format your code to make it easier to read and test:

  1. After you copy/paste your code into the editor, select it by dragging your cursor over it then click the (</>) button in the toolbar to automatically wrap your code in backticks. (You can click on the animated demo image below to enlarge it.)

  1. Manually add three backticks on a new line above your code and on a new line after your code. Note that a backtick is NOT the same as a single quote('). To find the backtick key on your keyboard, see this post.

To see changes to your post as you make them, you can click the (M+) button on the toolbar to bring up the rich text editor:

Hi @Mbutt

This doesn’t look right:

until [[ 𝑄𝑈𝐸𝑆𝑇𝐼𝑂𝑁 =\~? ]]

Try this:

until [[ 𝑄𝑈𝐸𝑆𝑇𝐼𝑂𝑁 =~ \? ]]

Happy coding

Ok so I’m unable to edit my original post so here’s the code with recommendations from the replies! Unfortunately couldn’t figure out how to post a link to my github since freecodecamp doesn’t let you do that for security reasons. But hopefully this code will be editable. Ill attach a screenshot too of the step I’m on, hopefully that helps.

Course URL: https://raw.githubusercontent.com/freeCodeCamp/learn-bash-scripting-by-building-five-programs/main/tutorial.json

#!/bin/bash 

# Program to tell a person's fortune

echo -e "\n~~ Fortune Teller ~~\n" 

RESPONSES=("Yes" "No" "Maybe" "Outlook good" "Don't count on it" "Ask again later")

N=$(( $RANDOM % 6 ))

GET_FORTUNE() {

  if [[ ! $1 ]]

  then

    echo Ask a yes or no question:

  else

    echo Try again. Make sure it ends with a question mark:

  fi




  read QUESTION

}




GET_FORTUNE

until [[ $QUESTION =~ \?$ ]]

do

  GET_FORTUNE again

done




echo ${RESPONSES[$N]}

Did you try the suggestion from @Teller :backhand_index_pointing_up:?

I did! didn’t do anything :moai: For reference, here’s what freecodecamp says in the hints:

Your above code does not reflect @Teller’s suggestion. Please try again.

Here’s the code with teller’s suggestion copy and pasted. Unfortunately still not working :smiling_face_with_tear:

When showing your code, do not screenshot it. Instead copy the full code text here. A screenshot does not help us help you.

Ps. A screenshot is helpful though to show any error messages received and the state of your environment

Below is the code. I’ve also attached a screenshot of the step I am on and the error message. Here is the course URL: https://raw.githubusercontent.com/freeCodeCamp/learn-bash-scripting-by-building-five-programs/main/tutorial.json

#!/bin/bash 

# Program to tell a person's fortune

echo -e "\n~~ Fortune Teller ~~\n" 

RESPONSES=("Yes" "No" "Maybe" "Outlook good" "Don't count on it" "Ask again later")

N=$(( $RANDOM % 6 ))

GET_FORTUNE() {

  if [[ ! $1 ]]

  then

    echo Ask a yes or no question:

  else

    echo Try again. Make sure it ends with a question mark:

  fi




  read QUESTION

}




GET_FORTUNE

until [[ 𝑄𝑈𝐸𝑆𝑇𝐼𝑂𝑁 =~ \? ]]

do

  GET_FORTUNE again

done




echo ${RESPONSES[$N]}


Did you add any extra code? If so, it might be causing the tests to fail. I see the step after the one you are on asks you to add a GET_FORTUNE call before the until loop. Looks like your code already has that. Perhaps try deleting it?

Hi @Mbutt

I went ahead and combined your posts for you. In the future, just reply to the original thread to add further updates.

Happy coding

Hi @Mbutt

image

  • A $ is missing before QUESTION
  • Your code is missing a $ after ?

Happy coding

I think I can see the issue in the until line. You’re missing the $ before QUESTION and also after the ?. It should be until [[ QUESTION =~ \? ]]

I had to look at that line twice too :sweat_smile: The $ at the end is what checks that the question actually ends with ?

Did you just repeat what the earlier post said? :joy:

Hey!

So Prajaktaa and teller were right about fixing that line of code but unfortunately still not working :smiling_face_with_tear: I have a feeling its what moT01 suggested (though their recommendation of which line of code might be messing up wasn’t right). I think I might just have to restart the course again and hopefully everything goes smoothly. Thanks everyone for the suggestions though!

You can use the reset button in CodeRoad and it should take you to the start of the lesson you are on.