In Case of Many Options & When and Then


#1

I had trouble earlier in this lesson when first asked to refactor a case statement. The program ran. I walked through every line to make sure there weren’t any typos. There wasn’t an error, but after a prolonged execution period of the answer being checked, my answer was marked as incorrect.

I went back and replaced all the quotes in case there was a character encoding issue. I then switched the case statement from compact to expanded (instead of using ‘then’ to compress to a single line as either answer was acceptable). The program still ran as expected, but the answer was still marked wrong.

I eventually gave up and allowed the system to input its own solution. The only difference I noticed was extra lines being skipped between the comment and the custom code.

But again, I am running into the same problem with a question further in the lesson (In Case of Many Options).

puts "What's your favorite language?"
language = gets.chomp

case language
when "Ruby" then puts "Ruby is great for web apps!"
when "Python" then puts "Python is great for science."
when "JavaScript" then puts "JavaScript makes websites awesome."
when "HTML" then puts "HTML is what websites are made of!"
when "CSS" then puts "CSS makes websites pretty."
else puts "I don't know that language!"
end

The program runs as expected. I made only minimal edits to the original code, so there shouldn’t be any character encoding issues. The execution takes an extended period (at least 45 seconds of processing/thinking) before marking my answer as incorrect.

Can anyone tell me what I’m doing wrong?

Oh, and I have tried using both double-spacing and tabbing to indent the code, as well as not indenting, in case there was a nuance with the backend test.

I don’t want to skip this question like the last one as I keep hitting a wall with the case statements in this lesson and am obviously making a mistake that I need to learn from. Please, help.


#2

Also tried expanded form formatted like this:

puts "What's your favorite language?"
language = gets.chomp

case language
when "Ruby"
  puts "Ruby is great for web apps!"
when "Python"
  puts "Python is great for science."
when "JavaScript"
  puts "JavaScript makes websites awesome."
when "HTML"
  puts "HTML is what websites are made of!"
when "CSS"
  puts "CSS makes websites pretty."
else
  puts "I don't know that language!"
end

https://www.codecademy.com/courses/learn-ruby/lessons/the-zen-of-ruby/exercises/in-case-of-many-options


#3

Your code passes in my test. Have you entered a language at the prompt?


#4

Yes. I entered a response each time I ran my code. The program output its response. There weren’t any errors. The answer is just being marked as incorrect after a 45sec (or more) wait following the output. I can’t get the system to mark it as correct even though it runs correctly each time, which is the same issue I had with the “When and Then” question earlier in the lesson.

Maybe there is a bug with the answer verification (?), but I haven’t seen anyone else suggest this in the forum. Though, if there is a bug, that would suggest a change to these two questions recently or in the verification test if others haven’t reported a similar issue.


Update: I reported the question as having a bug and also referenced the question earlier in the lesson to look into as well. Thank you for verifying the code on your end, which at least reassures me that I’m doing it correctly and can move on. Hopefully the tech team can figure out what’s wrong with the answer verification. Thanks again for your prompt response.


#6

Have you tested in an alternate browser? I used Firefox for testing.


#7

Good question. I just logged in with Safari to check, and it worked. Only having trouble in the latest (stable) version of Chrome, but maybe Chrome needs to be restarted or my computer rebooted (usual technical troubleshooting steps). It’s just strange that I wasn’t having any technical problems with the other questions. I’ve been on here for several hours today and was on here yesterday and the day before and have yet to exit my browser. Only problems were with the case statement questions in this lesson being marked as correct. If I run into an issue like this again, I’ll just try in Safari before posting to the forums. Thanks.


#8

Thanks gentlemen, switching from Chrome to Firefox (and copying-pasting) your code (with then) worked for me too.


#9

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