Update


#1



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


I went through each line and I am stuck as to why the syntax isn't pushing through.

Oops, try again. Your syntax doesn't look quite right. Feel free to peek back at the first exercise if you need help!

(ruby):24: syntax error, unexpected tFID, expecting keyword_then or ';' or '\n'
(ruby):32: syntax error, unexpected keyword_when, expecting $end
when 'display'
^


movies = {
    Moana: 5,
    Arrival: 5,
    Fast8: 5
}
    puts "Add, update, display, or delete a movie."

choice = gets.chomp

case choice
when 'add'
    puts "What movie do you want to add?"
    title = gets.chomp
    if movies[title.to_sym].nil?
    puts "What's the rating on a scale of 1-5?"
    rating = gets.chomp
    movies[title.to_sym] = rating.to_i
    puts "#{title} has been added with a rating of #{rating}."
    else
    puts "That movie already exists!"
end
when 'update'
    puts "Which movie?"
    title = gets.chomp
    if movies[title.to_sym]nil?
    puts "No bueno."
    else
        puts "Set a new rating."
    rating = gets.chomp
    movies[title.to_sym] = rating.to_i
    puts "#{title} is now updated with a rating of #{rating}!"
end
when 'display'
    puts "Movies!"
when 'delete'
    puts "Deleted!"
else
    puts "Error!"
end


#2

when you are checking if something is equal to something you need to use a double = sign (==) .

You have two places you need that.


#3

... is a little bit undescribed. It's just out here with 'when'. Mightn't have nay to do with the problem but raises a brow or two.


#4

movies[title.to_sym] == rating.to_i

??


#5

I'm feeling a bit confused. Can you clarify?


#6

The end keyword is valid, but the placement in the structure would have us believe it is somehow paired with the when which we know to be false, as it is paired with the if in actual fact. Ruby indentation is ignored by the interpreter, but useful to the reader to delineate block structures. It is semantic in nature so should be suggestive of the right object.

No. What you have in the original code is correct.

This line is missing the dot. See your line higher up for reference.


#7

You are so awesome! I understand now.

The spacing itself doesn't block the code but the indentation aligns itself with the correct object.

The dot! Long study sessions play with my eyes.

Thank you so much for taking the time. Truly appreciated.


#8

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