I am getting this error #<Question:0x0000022164ee9210>
, as of my knowledge there is nothing wrong with the code.
prompt1 = "Roses are what, \n a) Blue ,\n b) Red \n c)Orrange"
prompt2 = "Voilets are what, \n a) Blue ,\n b) Red \n c)Orrange"
prompt3 = "I love who ?, \n a)Them ,\n b) everyone \n c)You"
This is the questions classs
class Question
attr_accessor :prompt, :answer
def initialize(prompt,answer)
@prompt = prompt
@answer = answer
end
end
questions = [
Question.new(prompt1,"b"),
Question.new(prompt2, "a"),
Question.new(prompt3,"c")
]
This is the testing function that will check the answer. and display results.
def testing (questions)
answer = ""
score = 0
for question in questions
puts question
answer = gets.chomp()
if answer == question.answer
score +=1
end
end
puts "\n You got #{score} questions right. out of #{questions.length} questions. "
end
testing(questions)
You are looking at the output of puts question
.
Replace that by print question.prompt