0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Ruby学習#32 Building a Quiz

Posted at

class Question
attr_acessor :prompt, :answer
def initialize(prompt, answer)
@prompt = prompt
@answer = answer
end
end

p1 = "What Color are apples?\n(a)red\n(b)purple(c)orange"
p2 = "What Color are bananas?\n(a)pink\n(b)red(c)yellow"
p3 = "What Color are pears?\n(a)yellow\n(b)green(c)orange"

questions = [
Question.new(p1, "a"),
Question.new(p2, "c"),
Question.new(p3, "b")
]

def run_test(questions)
answer = ""
score = 0
for question in questions
puts question.prompt
answer = gets.chomp()
if answer == question.answer
score += 1
end
end
puts ( "You got " + score + "/" + question.length())
end

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?