I want to ask a person how much they know about their friends and what their favorite game is. I want to print it after my loop iteration gathers the data. This is what I tried. I want the user to input their friends' name and their friends' favorite game and later print that, but I thought I did that with the two gets.chomp for friend and game:
friendgame_hash = {} #this is where the hash starts I believe
input = "" #set input initially to nil
friend = "" #set friend to nil
game = "" #set game to nil
# starts the input from the user to get the name of their friend and favorite game
puts "Enter name of friend, then their favorite game: or Press Enter to quit " #
input = gets.chomp
while input != "" do #continue getting name of friend and their favorite game
(puts "Enter name of friend: ")
friend = gets.chomp
puts "Enter friends favorite game: "
game = gets.chomp
friendgame_hash[friend] = game #if understanding correctly hash key=friend value=game
input = gets.chomp #if user just presses enter they get out of while loop
end
puts "Here is the content that was in the hash: "
friendgame_hash.each do |key, value|
puts "#{key} => #{value}"
end
But I get the following errors:
(eval):20: (eval):20: compile error (SyntaxError)
(eval):8: odd number list for Hash
(eval):9: syntax error, unexpected tIDENTIFIER, expecting '}'
friend = gets.chomp
^
(eval):15: syntax error, unexpected '}', expecting kEND
(eval):18: syntax error, unexpected kDO_COND, expecting kEND
friendgame_hash.each do |key, value|
^
(eval):18: syntax error, unexpected '|', expecting '='
I don't know where I am wrong. Any help would be outstanding. I am curious if I am on the right path or am I going about the problem wrong. Any assistance would be much appreciated.
dokeyword afterwhileyou don't need the{and you should replace}withendfriendgame_hashfor both