I am in the midst of learning how to use Ruby with Code Academy and I am
stuck. I have a case block that works perfectly fine, but gives me an
error when I try to run it. The error is oops, try again. It looks like
your case statement doesn't puts 'Added!' when choice == 'add'.
The code I am using is:
case choice
when "add"
puts "Added!"
when "update"
puts "Updated!"
when "display"
puts "Movies!"
when "delete"
puts "Deleted!"
else
puts "Error!"
end
Any help on this would be great. Thanks!
···
--
The case is correct:
2.0.0p195 :013 > choice = "add"
=> "add"
2.0.0p195 :014 > case choice
2.0.0p195 :015?> when "add"
2.0.0p195 :016?> puts "Added!"
2.0.0p195 :017?> when "update"
2.0.0p195 :018?> puts "Updated!"
2.0.0p195 :019?> when "display"
2.0.0p195 :020?> puts "Movies!"
2.0.0p195 :021?> when "delete"
2.0.0p195 :022?> puts "Deleted!"
2.0.0p195 :023?> else
2.0.0p195 :024 > puts "Error!"
2.0.0p195 :025?> end
Added!
so that means that choice doesn't contain what you think. A wild
guess: if you are reading it from user input with gets, maybe you are
not removing the new line character (\n) at the end?
If that's the case, you can do that with the chomp method:
choice = gets.chomp
Hope this helps,
Jesus.
···
On Tue, Dec 2, 2014 at 6:02 PM, Gregg Martinson <gregg.martinson@gmail.com> wrote:
I am in the midst of learning how to use Ruby with Code Academy and I am
stuck. I have a case block that works perfectly fine, but gives me an error
when I try to run it. The error is oops, try again. It looks like your case
statement doesn't puts 'Added!' when choice == 'add'.
The code I am using is:
case choice
when "add"
puts "Added!"
when "update"
puts "Updated!"
when "display"
puts "Movies!"
when "delete"
puts "Deleted!"
else
puts "Error!"
end
Any help on this would be great. Thanks!
That was all in the code that I didn't clip. My guess is that codeacademy
has a bug. Thanks Jesus!
···
--
On Tue, Dec 2, 2014 at 11:11 AM, Jesús Gabriel y Galán < jgabrielygalan@gmail.com> wrote:
On Tue, Dec 2, 2014 at 6:02 PM, Gregg Martinson > <gregg.martinson@gmail.com> wrote:
> I am in the midst of learning how to use Ruby with Code Academy and I am
> stuck. I have a case block that works perfectly fine, but gives me an
error
> when I try to run it. The error is oops, try again. It looks like your
case
> statement doesn't puts 'Added!' when choice == 'add'.
> The code I am using is:
> case choice
> when "add"
> puts "Added!"
> when "update"
> puts "Updated!"
> when "display"
> puts "Movies!"
> when "delete"
> puts "Deleted!"
> else
> puts "Error!"
> end
>
> Any help on this would be great. Thanks!
The case is correct:
2.0.0p195 :013 > choice = "add"
=> "add"
2.0.0p195 :014 > case choice
2.0.0p195 :015?> when "add"
2.0.0p195 :016?> puts "Added!"
2.0.0p195 :017?> when "update"
2.0.0p195 :018?> puts "Updated!"
2.0.0p195 :019?> when "display"
2.0.0p195 :020?> puts "Movies!"
2.0.0p195 :021?> when "delete"
2.0.0p195 :022?> puts "Deleted!"
2.0.0p195 :023?> else
2.0.0p195 :024 > puts "Error!"
2.0.0p195 :025?> end
Added!
so that means that choice doesn't contain what you think. A wild
guess: if you are reading it from user input with gets, maybe you are
not removing the new line character (\n) at the end?
If that's the case, you can do that with the chomp method:
choice = gets.chomp
Hope this helps,
Jesus.
This kind of thing has happened to me before on CA, tests failing when I know they are correct. Logging out and logging back in fixed it for me. :\
···
On 14-12-02 12:27 PM, Gregg Martinson wrote:
That was all in the code that I didn't clip. My guess is that codeacademy has a bug. Thanks Jesus!
--
Gregg Martinson - Saint Paul, Minnesota, Roseville Area High School, BS Mankato State University, MS Minnesota State University, Mankato | about.me
On Tue, Dec 2, 2014 at 11:11 AM, Jesús Gabriel y Galán > <jgabrielygalan@gmail.com <mailto:jgabrielygalan@gmail.com>> wrote:
On Tue, Dec 2, 2014 at 6:02 PM, Gregg Martinson > <gregg.martinson@gmail.com <mailto:gregg.martinson@gmail.com>> wrote:
> I am in the midst of learning how to use Ruby with Code Academy
and I am
> stuck. I have a case block that works perfectly fine, but gives
me an error
> when I try to run it. The error is oops, try again. It looks
like your case
> statement doesn't puts 'Added!' when choice == 'add'.
> The code I am using is:
> case choice
> when "add"
> puts "Added!"
> when "update"
> puts "Updated!"
> when "display"
> puts "Movies!"
> when "delete"
> puts "Deleted!"
> else
> puts "Error!"
> end
>
> Any help on this would be great. Thanks!
The case is correct:
2.0.0p195 :013 > choice = "add"
=> "add"
2.0.0p195 :014 > case choice
2.0.0p195 :015?> when "add"
2.0.0p195 :016?> puts "Added!"
2.0.0p195 :017?> when "update"
2.0.0p195 :018?> puts "Updated!"
2.0.0p195 :019?> when "display"
2.0.0p195 :020?> puts "Movies!"
2.0.0p195 :021?> when "delete"
2.0.0p195 :022?> puts "Deleted!"
2.0.0p195 :023?> else
2.0.0p195 :024 > puts "Error!"
2.0.0p195 :025?> end
Added!
so that means that choice doesn't contain what you think. A wild
guess: if you are reading it from user input with gets, maybe you are
not removing the new line character (\n) at the end?
If that's the case, you can do that with the chomp method:
choice = gets.chomp
Hope this helps,
Jesus.