I7/20 help


#1



Hi I’m stuck on this topic please help.

https://www.codecademy.com/courses/ruby-beginner-en-1o8Mb/3/3?curriculum_id=5059f8619189a5000201fbcb#

I keep getting these error messages.
(ruby):15: unterminated string meets end of file
(ruby):15: syntax error, unexpected $end, expecting keyword_end


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

Replace this line with your code. 



#2

@slasher2468,
With

language = "Ruby"

you are using the assigment operator =
you assign the string Value "Ruby" to the variable language

But in your when-clause you should use a comparison operator ===
you want to compare the referenced-Value of variable language to a string Value

http://stackoverflow.com/questions/3154876/ruby-comparison-operators-vs


#3

I changed it to this but it still doesn’t work.

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


#4

@slasher2468,
Your case-when-else-end syntax is incorrect......
Have a read
http://stackoverflow.com/questions/948135/how-can-i-write-a-switch-statement-in-ruby?rq=1


#5

I read that but I still can’t get my code to work.

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


#6

@slasher2468,
The syntax for a CASE WHEN ELSE END statement
As case you present a value
as when you present a value which will be compared with the case-value
( internally the === comparison operator )

==== Example 1. ======

test="ok"
case test
when "ok"
  puts "it is ok"
else
  puts "don't know"
end

==== Example 2. ======

test='ok'
case true
when test === "ok"
  puts "2nd it is ok"
else
  puts "2nd don't know"
end

#7

also watch your quotes at the bottom. if you put that in verbatim, you'll have a pretty easy to fix error but its still important to note


#8

I passed it with this code but it only worked if i put an unknown coding language
here is my code: 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


#9

@slasher2468
For instance if you
enter the language "Ruby"

language == "Ruby"

this expression will result in a Boolean true

Then
The comparison is done by comparing
- the object in the when-clause ( which is the Boolean true )
- with the object in the case-clause _( which is the =string=Value "Ruby"
using the === operator.

Please READ !!!!!
https://discuss.codecademy.com/t/i7-20-help/43006/6?u=leonhard.wettengmx.n
and
http://stackoverflow.com/questions/948135/how-can-i-write-a-switch-statement-in-ruby?rq=1


#10

yup! remove the
when language == "Ruby"
bit, and replacing it with
when "Ruby"
will cause it to work. read what leonhard posted. Its good information


#11

puts “I don't know that language!

just put a comma at the end