6. Error. Error


#1



can someone please help me? I'm having an issue and cannot figure out what is wrong with my code


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

this is my error:

(ruby):25: syntax error, unexpected keyword_when, expecting keyword_end
when 'update'
^
(ruby):27: syntax error, unexpected keyword_when, expecting keyword_end
when 'display'
^
(ruby):29: syntax error, unexpected keyword_when, expecting keyword_end
when 'delete'
^
(ruby):33: syntax error, unexpected $end, expecting keyword_end

this is my code:

movies={
"300"=> 4,
"transformer" => 3.5,
"fight club"=> 2,
}

puts "what would you like to do?"
puts "type 'add' to add a movie"

choice=gets.chomp

case choice
when 'add'
puts "Please pick a movie title"
title=gets.chomp.to_sym

if
    movies[title.to_sym].nil?
    puts "please give me your rating"
rating=gets.chomp
movies[title.to_sym]=ratings.to_i

    puts " your movie #{title } has been added with your rating of #{rating }."
else
    puts "#{title} has already been added with a rating of #{rating}!"

when 'update'
puts "Updated!"
when 'display'
puts "Movies!"
when 'delete'
puts "deleted!"
else
puts "Error!"
end


Replace this line with your code.


#2

movies= {
  "300" => 4,
  "transformer" => 3.5,
  "fight club" => 2, 
}

puts "what would you like to do?"
puts "Type 'add' to add a movie"

choice = gets.chomp

case choice
  when 'add'
  puts "Please pick a movie title"
  title = gets.chomp.to_sym

  if
    movies[title.to_sym].nil?
    puts "please give me your rating"
    rating = gets.chomp
    movies[title.to_sym]=ratings.to_i

    puts " your movie #{title } has been added with your rating of #{rating }."
  else
    puts "#{title} has already been added with a rating of #{rating}!"

when 'update'
puts "Updated!"
when 'display'
puts "Movies!"
when 'delete'
puts "deleted!"
else
puts "Error!"
end

An if / else statement must be closed by an end tag.


#3

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