Raindrops.sh - elif/else seem to not work properly

Got 4/18 tests correct. The if statement ( $COUNT % 3 ) works fine, but everything breaks down once it hits the first elif statement.

COUNT=$((counter++))

if [[ $(( $COUNT % 3 )) -eq 0 ]]
then
echo “Pling”

elif [[ $(( $COUNT % 5 )) -eq 0 ]]
then
echo “Plang”

elif [[ $(( $COUNT % 7 )) -eq 0 ]]
then
echo “Plong”

else
echo $COUNT
fi

Hi @zentropy and welcome to the Exercism forum!

For helping with debugging, please copy and paste the whole failure message you get (from online editor or commandline), as text in a code block. See below for the code block button.

I believe this is not all of the code you wrote. Can you post all you have and put it into a code block with the code block button:

grafik

Thank you!

1 Like

If the input is 15, the program is supposed to print PlingPlang. What does your script print when the input is 15?

You’re supposed to be testing the value in $1. I’m not sure what you’re counting.

Thanks. Will make that change.

Yes. Still getting the same 4/18. Again seems like elif/else aren’t working. I know there’re more efficient ways to do this, but I’d like to first see if I can accomplish the job this way.

function raindrops() {
COUNT=“”
for COUNT in $(($counter+1)); do

if [[ $(( $COUNT % 3 == 0 )) ]]
    then 
        echo "Pling"

elif [[ $(( $COUNT % 5 == 0)) ]]
    then  
        echo "Plang"

elif [[ $(( $COUNT % 3 && $COUNT % 5 == 0 )) ]]
    then  
        echo "PlingPlang"

elif [[ $(( $COUNT % 7 == 0 )) ]]
    then 
        echo "Plong"

elif [[ $(( $COUNT % 5 && $COUNT % 7 == 0 )) ]]
    then 
        echo "PlangPlong"

elif [[ $(( $COUNT % 3 && $COUNT % 5 && $COUNT % 7 == 0 )) ]]
    then 
        echo "PlingPlangPlong"
else 
    echo $COUNT
fi  

done
}
raindrops “$@”

What happens in this code when the input is 15? Which statements are executed in what order?

Also, your code would be easier to read if you put it all into a codeblock.

When attempting 15 as input:

`assert_output “PlingPlang”’ failed

– output differs –
expected : PlingPlang
actual : Pling

3, 6, 9, & 27 pass as they are factors of 3.
Thanks. I’ll post any code in a code block

Which lines of your code are run? What does your code do? Do you understand the behavior of your code for that input?