Last active
January 1, 2018 23:41
-
-
Save ryanckulp/70ab24ff63b9542951288ec977a5a62c to your computer and use it in GitHub Desktop.
a sample flash card application in Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
questions = { | |
'one' => {text: "What is 2 + 2?", answer: 4}, | |
'two' => {text: "What is 4 + 7?", answer: 11}, | |
'three' => {text: "What is 7 + 3?", answer: 10}, | |
} | |
user_answers = { | |
'one' => 4, | |
'two' => 9, | |
'three' => 10 | |
} | |
def addition_problem(user_answer, correct_answer) | |
if user_answer == correct_answer | |
true | |
else | |
false | |
end | |
end | |
total_correct = 0 | |
user_answers.each do |question_number, user_answer| | |
correct_answer = questions[question_number][:answer] | |
if addition_problem(user_answer, correct_answer) # => will return true or false | |
total_correct +=1 | |
end | |
end | |
puts "You scored #{total_correct} out of #{user_answers.count} correct!" | |
# => You scored 2 out of 3 correct! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment