There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
When I enter “Add”, I get “Added!”, but when I enter “add”, it returns error? What gives? You’d think you can’t downcase lower case strings any further???
choice = gets.chomp.downcase!
case choice
when “add”
puts “Added!”
when “delete”
puts “Deleted!”
when “update”
puts “Updated!”
when “display”
puts “Movies!”
else
puts “Error!”
end
Hi! hello, I’m having some issues making some exercises, specially with this one about case statements… and it doesn’t allow me to keep going with my lessons…
Can anyone help me to fix this?
Ah, interesting! Have you tried switching to a different browser? Perhaps clearing cache?
I was just posting because the first fix I tried (different browser) worked, in the hope it might help others, I’m not suggesting Firefox is the silver bullet!
Because it is JavaScript that is running server-side (i.e. checking your code), then I would expect this to be browser agnostic. I cleared the cache but it didn’t seem to resolve the problem. In the end, I passed the lesson by being able to select the ‘Next’ button, even when the ‘execution expired’ message appeared.
Could anyone help troubleshoot where i’ve gone wrong with the below code please?
As required in the question, i setup the case conditions, and after running, it gives me the result required. Unfortunately they still tell me I’m not receiving the correct outcome: It looks like your case statement doesn’t puts ‘Added!’ when choice == ‘add’.
ah ok i realize im replying to my own comment but just in case anyone gets the same issue, i don’t think theres anything wrong with my code, just that the program is a little nitpicky.
movies = {
StarWars: 4.8,
Divergent: 4.7
}
puts "What would you like to do? "
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
Its exactly the same except for the first few sentances.
If you have the statements on the same line as the conditions, then you must use ; or then keyword. All three forms below will work:
case choice
when "add"
puts "Added!"
when "update"
puts "Updated!"
else
puts "Error!"
end
case choice
when "add" then puts "Added!"
when "update" then puts "Updated!"
else puts "Error!"
end
case choice
when "add"; puts "Added!"
when "update"; puts "Updated!"
else puts "Error!"
end