Comparing two arrays: answers vs. answer key

I’m trying to create a simple quiz, get user answer input and then
compare the users answers to the correct answers and then display the
percentage correct (or the “grade”).

My puts statement at the very bottom was for me to verify the users
answers were being added to the user answer array.

Thanks for any help!

my code is attached as a file. sorry for the inconvenience

You’ll want something like this:

if answer == question[:answer]
puts “correct”
puts “wrong”

Or maybe this:

puts ( answer == question[:answer] ? ‘correct’ : ‘wrong’ )

The first suggestion works perfectly! Thank you!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs