Hash rocket style not accepted


#1

In exercises 1 and 2, you are prompted to create a hash using the hash rocket style. However, if you follow the exercise through, you get lots of errors with your case statement on exercise 3. You basically cannot complete the exercise (“Else statement not working” / user input for “Add” etc. not accepted).

I figured out this was the case when I raised it with an adviser and was given replacement code (no analysis of my existing code). His code contained the Ruby 1.9 style for creating hashes (Inception: 4 rather than “Inception” => 4). When I replaced my original hash with the Ruby 1.9 style everything started working.

Original code in case I’ve done something stupid:

movies = {
  "Life of Brian" => 4
  }

puts "Give me input"
choice = gets.chomp

case choice
  when "add"
    puts "Added!"
  when "update"
    puts "Updated"
  when "display"
    puts "Movies!"
  when "delete"
    puts "Deleted!"
  else
    puts "Error!"
end

#2

My guess is that you picked “update” as input, and you’re not printing the right message there

That submission test looks at your choice variable and then checks whether the corresponding message was printed - so it won’t care about how you wrote the code so long as it matches the described behaviour


#3

I doubt it was the hash rockets causing trouble. They are still widely in use(always will be), in fact they are still completely necessary for Ruby Hashes and I hardly see the ‘new’ way implemented.
Do you have your old code?


#4

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