require 'cgi'
require 'csv'

cgi = CDI.new
params = chi.params

#クイズのデータをCSVから読み込む
quizzes = { "初級" => [], "中級" => [], "上級" => []}
CSV.foreach('quizzes.csv',headers: true) do |row|
  quizzes[row['level']] << {
    question: row['quwstion']
    choices: [row['choice1'],row['choice2'],row['choice3']],
    answer: row['answer']
  }
end

score = {"初級" => 0,"中級" => 0,"上級" => 0}
["初級","中級","上級"].each do |level|
quizzes[level].each do |quiz|
  if params[quiz[:question]] && params[quiz[:question]][0] == quiz[:answer]
    scord[level] += 1
  end
end
end

puts cgi.header("text/html")
puts "<!DOCTYPE html>"
puts "<html>"
puts "<head>"
puts " <title>結果</title>"
puts "</head>"
puts "<body>"
puts " <h1>結果</h1>"
