#Two-fer problem

8 messages · Page 1 of 1 (latest)

cold gorge
#

I have attempted the first exercise in bash-scripting, and the wording of the question is a bit confusing to me. Here's my implementation, it passes the first test, but fails the rest. Please help, I'll appreciate.

#!/usr/bin/env bash

read name

read likes

if [ ! -z "$name" ] && [ $likes == "yes" ]
then
    echo "One for $name, one for me."
else
    echo "One for you, one for me."
fi

Here's the error message I get for test 2:

(from function `assert_output' in file bats-extra.bash, line 394,
 in test file two_fer.bats, line 31)
  `assert_output "One for Alice, one for me."' failed

-- output differs --
expected : One for Alice, one for me.
actual   : One for you, one for me.
--
valid matrix
#

I don't understand Bash. I solved this exercise in Java. If your friend doesn't like cookies, wouldn't you judge based on the fact that their name is empty?

mossy raven
#

You're reading two lines from STDIN. Nothing is meant to be passed in via STDIN. There is one input via arguments, per the deleted stub and comments

cold gorge
#

Thank you all, I have made the corrections and passed all the tests successfully!

#

I removed the lines for reading stdin, then removed the && and only checked if argument one $1 was not empty to print it out, else print the other echo.

valid matrix
#

I'm really happy to hear that you've been successful, congratulations🎉

mossy raven
#

🎉

red garnetBOT
#

If everything is resolved, we ask that people react to the top/original post with a :white_check_mark: (:white_check_mark:). This indicates to others that this issue has been resolved and locks the thread.
If all the tests pass and you want to further improve your solution, we encourage you to use the "Request a Code Review" feature on the website!