Cannot get My Type to work, where have I gone wrong?


#1

Hey, I'm stuck here

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

Oops, try again. Make sure to test your program by choosing 'add'. Is the error I keep getting, I'm not sure why.

movies = {
    Batman: 1,
    Xmen: 2,
    Thor: 3
}

puts "Welcome to the cinema showings list how may I help you today?"
puts "--Type 'add' to add a movie title"
puts "--Type 'update' to update movie ratings"
puts "--Type 'display' to view currently showing movies"
puts "--Type 'delete' to delete movie titles currently on the list"
puts "What you like to do?"

choice = gets.chomp 
case choice
when "add" 
puts "Enter the movie title you would like to add:"
title = gets.chomp.downcase.
puts "tell me your rating out of 5?"
rating = gets.chomp
movies[title.to_sym] = rating.to_i 
puts "#{title}, has been added with a rating of #{rating}."
       when 'update'
       puts "Updated!"
    when 'display'
        puts "Movies!"
    when 'delete'
        puts "Deleted!"
    else
        puts "Error!"
end

I have I added the .to_sym and .to_i in the wrong spot or am I missing a ling of code, the code from excerise 4 worked just fine.


#2

title = gets.chomp.downcase.
puts "tell me your rating out of 5?"

Have you read the error message that ruby is giving you?
How does what ruby say relate to the above two lines?

18:in `<main>': private method `puts' called for "superman":String (NoMethodError)

That error message says which value is being used and says that puts is called on it as a method. Compare that with what you intend for those lines to be doing, and what code you've got there.


#3

My understanding is the lines are asking what title i want to add and what rating I want to give it. Yes I read the error and changing code, which I didn't save didn't help, and that I want to give it a rating out of 5, am I then putting the rating before the movie name in the code?


#4

The error message says that you're doing

"superman".puts

look at your code.

where is there anything similar to that? Where is the "superman" value, and where is there a .puts immediately following? That is what the error message says it crashes.


#5

movies={Batman:1,Xmen:2,Thor:3}puts"WelcometothecinemashowingslisthowmayIhelpyoutoday?"puts"--Type'add'toaddamovietitle"puts"--Type'update'toupdatemovieratings"puts"--Type'display'toviewcurrentlyshowingmovies"puts"--Type'delete'todeletemovietitlescurrentlyonthelist"puts"Whatyouliketodo?"choice=gets.chompcasechoicewhen"add"puts"Enterthemovietitleyouwouldliketoadd:"title=gets.chomp.downcase.puts"tellmeyourratingoutof5?"rating=gets.chompmovies[title.to_sym]=rating.to_iputs"#{title},hasbeenaddedwitharatingof#{rating}."when'update'puts"Updated!"when'display'puts"Movies!"when'delete'puts"Deleted!"elseputs"Error!"end

You're using a .puts method right? That is what the error says. And it crashes, because that object has no such method. So, you need to find where you're using this method.
That object is only in a few places and there are only puts in a couple of places so look for where they are used.

I've made it easier for you:
In the text above which is your code but with newlines and spaces removed.. there is a .puts
You can use your browser's search function to find it (Ctrl+F)


#6

Thanks I think I'm good now. :slight_smile: