When add or 1


#1

How can I enter this so that gets.chomp will run the add when "add" is typed or "1" is typed?

In the example on the first page the author shows only with "add"

I would like to accept either, or.


#2

You need this lesson:

https://www.codecademy.com/en/courses/ruby-beginner-en-NFCZ7/2/2?curriculum_id=5059f8619189a5000201fbcb

And this lesson:

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


#3

I've already tried that though, keep getting an error message. My code is

when "add" || 1
    puts "What movie would you like to add?"
    title = gets.chomp
    puts "Rate the movie from 1 to 5"
    rating = gets.chomp
    movies[title] = rating
    puts "#{title} has been added with a rating of #{rating}."

#4
when "add" || 1

Why does one of your value has quotes and one doesn't? As far as I know, the user will always provide you with characters, not integers ^^.

EDIT: Nevermind, the syntax is different for multiple conditions in a when, use the comma instead:

when value1, value2

Sorry for the confusion.


#5

There were quotes because the user would type either "add" or 1. Option 1 is add.

I want to provide multiple ways for the user to enter an option.

ie) when "add" || "Add" || "ADD" | 1 etc.


#6

but thanks for your edit... it works. Confusing that the syntax is different for multiple conditions for a case statement, but lesson learned :slight_smile: