Building Five Programs - fortune.sh

Tell us what’s happening:

In fortune.sh the command echo -e “\n${RESPONSES[$N]}” isn’t working, when I click Run it says Your script should have the suggests “if” statement added correctly, I’m stuck

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 ))
echo -e “\n${RESPONSES[$N]}”

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
}

GET_FORTUNE

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

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36

Challenge Information:

Learn Bash Scripting by Building Five Programs - Build Five Programs

try using the Reset button and writing again, there may be something else in the file that is not recognised

Hi, I did the RESET multiple times, nothing!

what are the instructions for this step?

Add an empty line in front of where you print the response.

  1. Change the existing echo ${RESPONSES[$N]} line

and is it still there after you reset? it seems in the wrong place, it is giving a response before a question is asked

Ohh, the line was at the end of the script not after N=$(( RANDOM % 6 )), now it works ! Thx for your quick intervention !

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