Error, error!


#1


https://www.codecademy.com/en/courses/ruby-beginner-en-0i8v1/0/6?curriculum_id=5059f8619189a5000201fbcb

I keep getting this message on this code. Thanks again!

(ruby):24: syntax error, unexpected keyword_when, expecting $end
when 'display'
^

movies= {
    titanic: 4,
    hitch: 4,
    baywatch: 1
}
puts "what do you want to do?"
choice= gets.chomp

case choice
when "add"
    puts "add a new name"
    title = gets.chomp
 
    if movies[title.to_sym]= nil
        puts "give it a rating"
        rating = gets.chomp
        movies[title.to_sym] = rating.to_i
 
    puts "#{title}, #{rating}"
    else puts "already exist"
    end
when 'update'
    puts "updated"
end
when 'display'
    puts "displaying"
end
when'deleted'
    puts "deleted"
end
else
    puts "Error!"
end


#2

@eddderz,
The when itself does not have an end
The end of a when is as another when is encountered......

As soon as it encounters an end which is not part of another statement structure like an IF
then the case is =closed= and another when is not expected by the Interpreter....

http://stackoverflow.com/questions/948135/how-can-i-write-a-switch-statement-in-ruby
http://stackoverflow.com/questions/36052425/how-to-break-out-of-case-statement-in-ruby?noredirect=1&lq=1
http://stackoverflow.com/questions/8022865/how-to-break-out-of-a-case-while-in-ruby


#3

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