0% found this document useful (0 votes)
8 views1 page

Quiz Game Script!27

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Quiz Game Script!27

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

-- Define quiz questions and answers

local questions = {
{question = "What is the capital of France?", answer = "Paris"},
{question = "What is 5 + 7?", answer = "12"},
{question = "What planet is known as the Red Planet?", answer = "Mars"},
{question = "What is the largest ocean on Earth?", answer = "Pacific"},
{question = "Who wrote 'Romeo and Juliet'?", answer = "Shakespeare"},
{question = "What gas do plants absorb from the atmosphere?", answer = "Carbon
Dioxide"},
{question = "What is the square root of 64?", answer = "8"},
}

-- Player score
local score = 0
local totalQuestions = #questions
local askedQuestions = {}

-- Function to ask a random question


local function askQuestion()
-- Select a random question that hasn’t been asked yet
local questionIndex
repeat
questionIndex = math.random(1, totalQuestions)
until not askedQuestions[questionIndex]

local selectedQuestion = questions[questionIndex]


askedQuestions[questionIndex] = true -- Mark this question as asked

print(selectedQuestion.question)
local playerAnswer = io.read() -- Get player’s input

if playerAnswer:lower() == selectedQuestion.answer:lower() then


print("Correct!")
score = score + 1
else
print("Wrong! The correct answer was " .. selectedQuestion.answer)
end
print("-------------")
end

-- Main game loop


print("Welcome to the Quiz Game!")
for i = 1, totalQuestions do
askQuestion()
end

-- Display final score


print("Game Over!")
print("Your final score is: " .. score .. " out of " .. totalQuestions)

-- Give a message based on performance


if score == totalQuestions then
print("Perfect! You got all questions right!")
elseif score > totalQuestions / 2 then
print("Great job! You scored above average.")
else
print("Better luck next time! Try to improve your score.")
end

You might also like