Code comes out right but says that it doesn’t. Can someone help?
puts “What’s your favorite language?”
language = gets.chomp
case language
when “Ruby” then ‘Ruby is great for web apps!’
when “Python” then “Python is great for science.”
when “JavaScript” then “JavaScript makes websites awesome.”
when “HTML” then “HTML is what websites are made of!”
when “CSS” then “CSS makes websites pretty.”
else “I don’t know that language!”
end
You all were really close, but are slightly off when it comes to Ruby case syntax, the proper syntax is:
case language
when “Ruby” puts “Ruby is great for web apps!”
when “Python” puts “Pyhton is great for science”
…
else puts “I don’t know that language”
end
Essentially, the ruby interpreter ‘knows’ that the string after when in each case is the variable to be interpreted against each case, so therefore you do not need to state: when language == "Ruby" puts ...
etc.
Ultimately your syntax is wrong and that is why you are getting errors.
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
I’m stuck on this one also… Same code as member above error message (Oops, try again.
Make sure to convert your if/elsif/else construction into a case statement!
)
the correct info is on the console log however will not let me pass onto next step…
Instructions
Refactor the if/elsif/else statement in the editor into a tidy case statement.
Hint Example of refactoring, notice what’s not in the code
Here’s one way of structuring a case statement: case variable
when value1 then #Do something! when value2 then #Do something else!
…
when value9 then #Do another thing!
else
Do the default thing!
end This code needs to look like the example above ^
puts “What’s your favorite language?”
language = gets.chomp
if language == “Ruby”
puts “Ruby is great for web apps!” elsif language == “Python”
puts “Python is great for science.”
elsif language == “JavaScript”
puts “JavaScript makes websites awesome.”
elsif language == “HTML”
puts “HTML is what websites are made of!”
elsif language == “CSS”
puts “CSS makes websites pretty.” else
puts “I don’t know that language!”
end
Had the same problem as what @rodgeralien listed. But then used the normal case statement.Here’s the code:
puts “What’s your favorite language?”
language = gets.chomp
case language
when language = “Ruby”
puts “Ruby is great for web apps!”
when language = “Python”
puts “Python is great for science.”
when language = “JavaScript”
puts “JavaScript makes websites awesome.”
when language = “HTML”
puts “HTML is what websites are made of!”
when language = “CSS”
puts “CSS makes websites pretty.”
else
puts “I don’t know that language!”
end
I just learned you can puts first before the case begins:
puts "What's your favorite language?"
language = gets.chomp
puts case language
when "Ruby" then "Ruby is great for web apps!"
when "Python" then "Python is great for science."
when "JavaScript" then "JavaScript makes websites awesome."
when "HTML" then "HTML is what websites are made of!"
when "CSS" then "CSS makes websites pretty."
else "I don't know that language!"
end
I was getting the error message “Ooops, looks like your program doesn’t put “Ruby is great for web apps!”, when language == 'Ruby”
Summary: I changed == to = and it worked.
My successful code was as below:
puts “What’s your favorite language?”
language = gets.chomp
case language
when language = “Ruby” then puts “Ruby is great for web apps!”
when language = “Python” then puts “Python is great for science.”
when language = “JavaScript” then puts “JavaScript makes websites awesome.”
when language = “HTML” then puts “HTML is what websites are made of!”
when language = “CSS” then puts “CSS makes websites pretty.”
else
puts “I don’t know that language!”
end