Advertisement
JiiCeii

Quizz

Mar 11th, 2012
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.75 KB | None | 0 0
  1. local QUIZZ = {
  2.     print = function(self, n) print("Question ".. n.. ") ".. self[n].question .. "\n".. self[n].choices) end,
  3.     {question = "When have we walked on the Moon for the first time ?", choices = "A) 1964,\nB) 1969,\nC) 1974", answer = "B"},
  4.     {question = "When Michael Jackson died ?", choices = "A) 2009\nB) 2010\nC) 2011", answer = "A"}
  5. }
  6. local PLAYER = {
  7.     printScore = function(self) local s = 0; for i = 1, #QUIZZ do s = s + (self[i] == QUIZZ[i].answer and 1 or 0) end print("Your score is : ".. s.. "/".. #QUIZZ) end
  8. }
  9.  
  10. for i = 1, #QUIZZ do
  11.     QUIZZ:print(i)
  12.     PLAYER[i] = io.read():upper()
  13.     print((PLAYER[i] == QUIZZ[i].answer) and "Right !" or "Wrong !")
  14.     os.execute("pause")
  15.     os.execute("cls")
  16. end
  17.  
  18.  
  19. PLAYER:printScore()
  20. os.execute("pause")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement