Build Five Programs - Build Five Programs

Tell us what’s happening:

I’m not able to pass this test. The instructions say to add an until loop and call GET_FORTUNE again, but my solution still fails. I checked my code several times and I don’t see what I’m missing. Could someone help me?

Your code so far

#!/bin/bash
# Program to tell a persons fortune

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

RESPONSES=("Yes" "No" "Maybe" "Outlook good" "Don't count on it" "Ask again later")
N=$((RANDOM % 6))

function 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

    until [[ $QUESTION =~ \?$ ]]
    do
        GET_FORTUNE again
    done
}

GET_FORTUNE
echo "${RESPONSES[$N]}"

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:152.0) Gecko/20100101 Firefox/152.0

Challenge Information:

Build Five Programs - Build Five Programs

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/workshop-bash-five-programs/5f5904ac738bc2fa9efecf5a.md at main · freeCodeCamp/freeCodeCamp · GitHub

Can you include a screenshot of the instructions and the hint if there is one?

Yes, I just edited it

Can you carefully click the reset button and wait patiently for it to reset the test? Then copy the code that it gave you and do not edit it at all. Copy the code here for us.

#!/bin/bash

# Program to tell a persons fortune

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

RESPONSES=("Yes" "No" "Maybe" "Outlook good" "Don't count on it" "Ask again later")
N=$(( RANDOM % 6 ))

function 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
}

until [[ $QUESTION =~ \?$ ]]
do
  GET_FORTUNE
done

echo ${RESPONSES[$N]}

It seems like the until part is out of the function

Yeah, they had asked you to edit the call to get fortune earlier (in a previous step), but I guess you added a second call instead which it didn’t detect. My suggestion is to open a GitHub issue for the maintainers to fix the earlier step but you have to open the earlier step (via the hamburger menu in CodeRoad) and grab the text of that earlier step to show them. Can you try finding it now?

I didn’t read it carefully and added the until in the function

do you mind copying the text of the instruction instead of the image? As it is easier for developers to look for text rather than have to transcribe from an image.

So you know how to fix the issue yourself now btw?