First things first: let’s create a hash to hold our movies and their ratings. Next, let’s prompt the user for input so we can eventually store movie/ratings pairs in our hash.

favorite_foods = { vegetable: 'broccoli' } puts "Do you like coding in Ruby?" answer = gets.chomp
  1. A hash is a way of storing data with a specifiable key, as opposed to an array where the data is only accessible using numbers (or indices). It is created using a pair of curly braces { }.
  2. puts displays a message in the console. In this example, we ask if you like coding in Ruby.
  3. In order to get the user input, we have to call .chomp on gets.



Create a hash and assign it to the variable movies. Put in your favorite movie as the key, with a number rating for the value.


Prompt the user for input with puts and save that input in a variable called choice.

After pressing Run, make sure to enter some text in the console then hit enter to test your code!

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?