        <script>
      
const questions = [
    {
        number: 1,
        question: "What does the sign with a red circle and a white horizontal bar represent?",
        options: [
            { text: "No Entry", isCorrect: true },
            { text: "Stop", isCorrect: false },
            { text: "Yield", isCorrect: false },
            { text: "Pedestrian Crossing", isCorrect: false }
        ],
        image: 'https://ghanahighwaylaws.pages.dev/1.webp'  // Image URL for Question 1
    },
    {
        number: 2,
        question: "What does the sign with a black number in a red circle indicate?",
        options: [
            { text: "Parking Zone", isCorrect: false },
            { text: "Speed Limit", isCorrect: true },
            { text: "No Parking", isCorrect: false },
            { text: "School Zone", isCorrect: false }
        ],
        image: 'https://ghanahighwaylaws.pages.dev/2.webp'  // Image URL for Question 2
    },
    {
        number: 3,
        question: "What does this traffic sign mean?",
        options: [
            { text: "School Zone", isCorrect: false },
            { text: "Pedestrian Crossing Ahead", isCorrect: true },
            { text: "Bicycles Only", isCorrect: false },
            { text: "No Overtaking", isCorrect: false }
        ],
        image: 'https://ghanahighwaylaws.pages.dev/3.webp'  // Image URL for Question 3
    },
    {
        number: 4,
        question: "What does this sign mean?",
        options: [
            { text: "Stop", isCorrect: false },
            { text: "No Overtaking", isCorrect: true },
            { text: "Speed Limit Ahead", isCorrect: false },
            { text: "U-Turn Only", isCorrect: false }
       ],
        image: 'https://ghanahighwaylaws.pages.dev/4.webp'  // Image URL for Question 4
    },
    {
        number: 5,
        question: "What does this sign indicate?",
        options: [
            { text: "Hospital Zone", isCorrect: true },
            { text: "School Zone", isCorrect: false },
            { text: "Rest Area", isCorrect: false },
            { text: "First Aid Station", isCorrect: false }
       ],
        image: 'https://ghanahighwaylaws.pages.dev/5.webp'  // Image URL for Question 5
    },
    {
        number: 6,
        question: "What does the roundabout sign mean?",
        options: [
            { text: "Roundabout Ahead", isCorrect: true },
            { text: "Dead End", isCorrect: false },
            { text: "Pedestrian Zone", isCorrect: false },
            { text: "One Way", isCorrect: false }
        ],
        image: 'https://ghanahighwaylaws.pages.dev/6.webp'  // Image URL for Question 6
    },
    {
        number: 7,
        question: "What does this sign indicate?",
        options: [
            { text: "Sharp Bend Ahead", isCorrect: true },
            { text: "Slippery Road", isCorrect: false },
            { text: "Slow Down", isCorrect: false },
            { text: "Stop and Give Way", isCorrect: false }
       ],
        image: 'https://ghanahighwaylaws.pages.dev/7.webp'  // Image URL for Question 7
    },
    {
        number: 8,
        question: "What does the image of a traffic light in a triangle shape represent?",
        options: [
            { text: "Traffic Lights Ahead", isCorrect: true },
            { text: "Stop Sign", isCorrect: false },
            { text: "No Entry", isCorrect: false },
            { text: "Zebra Crossing", isCorrect: false }
         ],
        image: 'https://ghanahighwaylaws.pages.dev/8.webp'  // Image URL for Question 8
    },
    {
        number: 9,
        question: "What does a red circle with a white horizontal bar typically signify on a traffic sign?",
        options: [
            { text: "No Parking", isCorrect: false },
            { text: "No Entry", isCorrect: true },
            { text: "Yield", isCorrect: false },
            { text: "Pedestrian Crossing", isCorrect: false }
        ]
    },
    {
        number: 10,
        question: "Which of the following traffic signs is used to indicate a pedestrian crossing?",
        options: [
            { text: "A rectangular yellow sign with a pedestrian image", isCorrect: false },
            { text: "A circular blue sign with a pedestrian image", isCorrect: false },
            { text: "A triangular warning sign with a pedestrian image", isCorrect: true },
            { text: "A diamond-shaped red sign with a pedestrian image", isCorrect: false }
        ]
    },
    {
        number: 11,
        question: "What should you do when approaching an intersection with no traffic signals, but with other vehicles waiting at the stop lines?",
        options: [
            { text: "Stop and give way to vehicles on the right", isCorrect: true },
            { text: "Proceed without stopping", isCorrect: false },
            { text: "Yield to vehicles on the left", isCorrect: false },
            { text: "Use your horn to alert others", isCorrect: false }
       ],
        image: 'https://ghanahighwaylaws.pages.dev/11.webp'  // Image URL for Question 11
    },
    {
        number: 12,
        question: "What should you do if pedestrians are waiting to cross at a pedestrian crossing?",
        options: [
            { text: "Continue driving at the same speed", isCorrect: false },
            { text: "Slow down and prepare to stop", isCorrect: true },
            { text: "Speed up to pass the crossing quickly", isCorrect: false },
            { text: "Honk your horn to alert the pedestrians", isCorrect: false }
         ],
        image: 'https://ghanahighwaylaws.pages.dev/12.webp'  // Image URL for Question 12
    },
    {
        number: 13,
        question: "How should you approach a roundabout?",
        options: [
            { text: "Drive through without stopping", isCorrect: false },
            { text: "Yield to traffic coming from your left", isCorrect: true },
            { text: "Always stop before entering", isCorrect: false },
            { text: "Enter immediately without checking for oncoming traffic", isCorrect: false }
        ],
        image: 'https://ghanahighwaylaws.pages.dev/13.webp'  // Image URL for Question 13
    },
    {
        number: 14,
        question: "When turning right at an intersection, what should you do?",
       "options": [
        { "text": "Yield to pedestrians and any vehicles with the right of way", "isCorrect": true },
        { "text": "Enter the left lane after turning", "isCorrect": false },
        { "text": "Stay in the right lane and signal clearly", "isCorrect": false },
        { "text": "Turn without using a signal", "isCorrect": false }
        ],
        image: 'https://ghanahighwaylaws.pages.dev/14.webp'  // Image URL for Question 14
    },
    {
        number: 15,
        question: "What is the correct action when entering a highway with merging lanes?",
        options: [
            { text: "Yield to vehicles already on the highway", isCorrect: true },
            { text: "Speed up to merge faster", isCorrect: false },
            { text: "Stop before merging", isCorrect: false },
            { text: "Ignore the signs and continue at your current speed", isCorrect: false }
        ],
        image: 'https://ghanahighwaylaws.pages.dev/15.webp'  // Image URL for Question 15
    },
    {
        number: 16,
        question: "What does it mean when a yellow traffic light is flashing?",
        options: [
            { text: "Stop immediately", isCorrect: false },
            { text: "Slow down and proceed with caution", isCorrect: true },
            { text: "Go through the intersection quickly", isCorrect: false },
            { text: "Wait until the light turns green", isCorrect: false }
        ]
    },
    {
        number: 17,
        question: "When you approach a school zone, what should you do?",
        options: [
            { text: "Speed up to pass quickly", isCorrect: false },
            { text: "Maintain your speed", isCorrect: false },
            { text: "Slow down and be extra cautious", isCorrect: true },
            { text: "Stop completely", isCorrect: false }
        ]
    },
    {
        number: 18,
        question: "When changing lanes, which of the following should you do first?",
        options: [
            { text: "Use your horn to alert others", isCorrect: false },
            { text: "Check your rearview mirror", isCorrect: true },
            { text: "Signal and then change lanes", isCorrect: false },
            { text: "Speed up before changing lanes", isCorrect: false }
        ]
    },
    {
        number: 19,
        question: "In a built-up area, what is the maximum speed limit for private vehicles?",
        options: [
            { text: "30 km/h", isCorrect: false },
            { text: "40 km/h", isCorrect: false },
            { text: "50 km/h", isCorrect: true },
            { text: "60 km/h", isCorrect: false }
        ]
    },
    {
        number: 20,
        question: "At an intersection with no traffic signs, who should have the right of way?",
        options: [
            { text: "The vehicle on the left", isCorrect: false },
            { text: "The vehicle on the right", isCorrect: true },
            { text: "The vehicle that arrives first", isCorrect: false },
            { text: "The larger vehicle", isCorrect: false }
        ]
    },
    
{
        number: 21,
        question: "You are driving behind another vehicle on a two-lane road and want to overtake. What should you check first?",
        options: [
            { text: "Whether the road ahead is clear", isCorrect: true },
            { text: "Whether the vehicle in front is signaling", isCorrect: false },
            { text: "Whether the road is one-way", isCorrect: false },
            { text: "Whether it’s a pedestrian zone", isCorrect: false }
        ]
    },
    {
        number: 22,
        question: "When driving in foggy weather, what should you do?",
        options: [
            { text: "Use high beams to see better", isCorrect: false },
            { text: "Reduce speed and use low beams", isCorrect: true },
            { text: "Stop until the fog clears", isCorrect: false },
            { text: "Increase speed to get through quickly", isCorrect: false }
        ]
    },
    {
        number: 23,
        question: "If you approach a pedestrian crossing and see a pedestrian waiting, what should you do?",
        options: [
            { text: "Continue driving", isCorrect: false },
            { text: "Slow down and prepare to stop", isCorrect: true },
            { text: "Use your horn to alert the pedestrian", isCorrect: false },
            { text: "Speed up to pass quickly", isCorrect: false }
        ]
    },
    {
        number: 24,
        question: "What is the correct action when you are driving on a multi-lane road and see a broken white line?",
        options: [
            { text: "You are allowed to change lanes", isCorrect: true },
            { text: "Do not change lanes", isCorrect: false },
            { text: "You must stop and yield", isCorrect: false },
            { text: "You should drive only in the left lane", isCorrect: false }
        ]
    },
    {
        number: 25,
        question: "When overtaking a cyclist, how far should you stay from the cyclist?",
        options: [
            { text: "At least 1 meter", isCorrect: false },
            { text: "At least 2 meters", isCorrect: true },
            { text: "At least 3 meters", isCorrect: false },
            { text: "No specific distance is required", isCorrect: false }
        ]
    },
    {
        number: 26,
        question: "At a crosswalk, what should you do when there are no pedestrians crossing?",
        options: [
            { text: "Stop and wait for a pedestrian to appear", isCorrect: false },
            { text: "Continue driving through the crosswalk", isCorrect: true },
            { text: "Speed through quickly", isCorrect: false },
            { text: "Stop and yield to other vehicles", isCorrect: false }
        ]
    },
    {
        number: 27,
        question: "What is the correct procedure when approaching a stop sign?",
        options: [
            { text: "Slow down and proceed if no vehicles are present", isCorrect: false },
            { text: "Stop completely and give way to traffic", isCorrect: true },
            { text: "Stop only if there are pedestrians", isCorrect: false },
            { text: "Only stop if there are other vehicles", isCorrect: false }
        ]
    },
    {
        number: 28,
        question: "When driving in heavy rain, you should always:",
        options: [
            { text: "Use high beams to see better", isCorrect: false },
            { text: "Increase speed to avoid delays", isCorrect: false },
            { text: "Slow down and increase following distance", isCorrect: true },
            { text: "Keep your windows down", isCorrect: false }
        ]
    },
    {
        number: 29,
        question: "When you see a police car with flashing lights, what should you do?",
        options: [
            { text: "Speed up to pass it quickly", isCorrect: false },
            { text: "Pull over to the side of the road", isCorrect: true },
            { text: "Continue driving at the same speed", isCorrect: false },
            { text: "Stop in the middle of the road", isCorrect: false }
        ]
    },
    {
        number: 30,
        question: "In bad weather conditions, when should you use your hazard lights?",
        options: [
            { text: "Only when stopping", isCorrect: false },
            { text: "When driving through poor visibility conditions", isCorrect: true },
            { text: "When overtaking", isCorrect: false },
            { text: "At night only", isCorrect: false }
        ]
    },
    {
        number: 31,
        question: "What does this red warning light on the dashboard indicate?",
        options: [
            { text: "Low fuel", isCorrect: false },
            { text: "Engine overheating", isCorrect: false },
            { text: "Low tire pressure", isCorrect: false },
            { text: "Need for oil change", isCorrect: true }
        ],
        image: 'https://ghanahighwaylaws.pages.dev/31.webp'  // Image URL for Question 31
    },
    {
        number: 32,
        question: "What should you do if your tire is visibly under-inflated?",
        options: [
            { text: "Continue driving to the nearest tire shop", isCorrect: false },
            { text: "Check tire pressure and inflate to the correct level", isCorrect: true },
            { text: "Replace the tire immediately", isCorrect: false },
            { text: "Ignore it, as the tire is still usable", isCorrect: false }
       ],
        image: 'https://ghanahighwaylaws.pages.dev/32.webp'  // Image URL for Question 32
    },
    {
        number: 33,
        question: "What should you check first if your car starts to overheat?",
        options: [
            { text: "Tire pressure", isCorrect: false },
            { text: "Engine coolant level", isCorrect: true },
            { text: "Brake fluid", isCorrect: false },
            { text: "Windshield washer fluid", isCorrect: false }
        ]
    },
    {
        number: 34,
        question: "How often should you change your oil in a vehicle?",
        options: [
            { text: "Every 500 km", isCorrect: false },
            { text: "Every 3,000–5,000 km", isCorrect: true },
            { text: "Every 10,000 km", isCorrect: false },
            { text: "Every 15,000 km", isCorrect: false }
        ]
    },
    {
        number: 35,
        question: "If your vehicle's brake warning light turns on while driving, what should you do?",
        options: [
            { text: "Continue driving as normal", isCorrect: false },
            { text: "Check your brake fluid and stop at a safe location", isCorrect: true },
            { text: "Immediately pull over and turn off the engine", isCorrect: false },
            { text: "Increase speed to avoid stopping", isCorrect: false }
        ]
    },
    {
        number: 36,
        question: "What is the purpose of checking your tire pressure regularly?",
        options: [
            { text: "To improve fuel efficiency", isCorrect: true },
            { text: "To ensure better grip and safety on the road", isCorrect: true },
            { text: "To enhance the appearance of the vehicle", isCorrect: false },
            { text: "To reduce engine noise", isCorrect: false }
        ]
    },
    {
        number: 37,
        question: "What does a yellow or orange dashboard warning light typically indicate?",
        options: [
            { text: "A serious vehicle malfunction that requires immediate attention", isCorrect: false },
            { text: "A minor issue that can be checked later", isCorrect: true },
            { text: "An issue with the air conditioning system", isCorrect: false },
            { text: "The fuel tank is nearly empty", isCorrect: false }
        ]
    },
    {
        number: 38,
        question: "What should you do if your vehicle begins to skid on a wet road?",
        options: [
            { text: "Steer sharply in the opposite direction", isCorrect: false },
            { text: "Turn the steering wheel left and right", isCorrect: false },
            { text: "Take your foot off the accelerator and steer into the skid", isCorrect: true },
            { text: "Apply the brakes quickly and forcefully", isCorrect: false }
        ]
    },
    {
        number: 39,
        question: "How can you maintain the battery life of your vehicle?",
        options: [
            { text: "Drive the vehicle at high speed", isCorrect: false },
            { text: "Make sure all electrical devices are turned off when the car is not in use", isCorrect: true },
            { text: "Only use the vehicle during the day", isCorrect: false },
            { text: "Keep the headlights on all the time", isCorrect: false }
        ]
    },
    {
        number: 40,
        question: "What is the function of the alternator in a vehicle?",
        options: [
            { text: "It cools the engine", isCorrect: false },
            { text: "It provides power to the lights", isCorrect: false },
            { text: "It charges the car battery", isCorrect: true },
            { text: "It regulates the tire pressure", isCorrect: false }
        ]
    }
];

// Shuffle and initialize questions
function shuffleArray(array) {
  for (let i = array.length - 1; i > 0; i--) {
    const j = Math.floor(Math.random() * (i + 1));
    [array[i], array[j]] = [array[j], array[i]];
  }
}

// Shuffle questions and set question numbers
shuffleArray(questions);
questions.forEach((question, index) => {
  question.number = index + 1;
});

let currentQuestion = 0;
let score = 0;
const wrongAnswers = [];

const questionText = document.getElementById("question-text");
const optionsContainer = document.getElementById("options-container");
const questionImageContainer = document.getElementById("question-image");
const submitQuizButton = document.getElementById("submit-quiz-button");
const resultContainer = document.getElementById("result-container");
const scoreText = document.getElementById("score-text");
const remarksText = document.getElementById("remarks");
const congratulationsText = document.getElementById("congratulations");
const correctAnswersText = document.getElementById("correct-answers-text");
const correctAnswersList = document.getElementById("correct-answers-list");
const correctFeedback = document.getElementById("correct-feedback");
const incorrectFeedback = document.getElementById("incorrect-feedback");
const nextButton = document.getElementById("next-button");

// Message container for thank you message
const messageContainer = document.getElementById("message-container");

// Add a variable to keep track of whether a question has been answered
let questionAnswered = false;

// Load the current question
function loadQuestion() {
    const current = questions[currentQuestion];  // Get the current shuffled question

    // Get the containers for question image and text
    const questionContainer = document.getElementById("question-container");

    // Get the question text container
    const questionText = document.getElementById("question-text");

    // Check if the current question has an image
    if (current.image) {
        // If there's an image URL, show the image container and set the image
        questionImageContainer.style.display = 'block';  // Ensure it's visible

        // Clear any existing image if it's already there
        questionImageContainer.innerHTML = '';  // Clear previous image

        // Create a new image element
        const image = document.createElement("img");
        image.src = current.image;  // Set the source to the image URL from the question
        image.alt = `Image for Question ${current.number}`;  // Alt text for the image

        

        // Append the image to the image container
        questionImageContainer.appendChild(image);
    } else {
        // If no image, hide the image container
        questionImageContainer.style.display = 'none';  // Hide the image container
    }

    // Display the question text
    questionText.innerHTML = `<span class='question-number'>${current.number}.</span> ${current.question}`;

    // Shuffle the options
    const shuffledOptions = [...current.options];
    shuffleArray(shuffledOptions);

    // Clear previous options
    optionsContainer.innerHTML = "";

    // Create and append the options buttons
    shuffledOptions.forEach((option, index) => {
        const button = document.createElement("button");
        button.innerHTML = option.text;
        button.addEventListener("click", () => selectOption(index, option.isCorrect));

        switch (index) {
            case 0:
                button.classList.add("option-a");
                break;
            case 1:
                button.classList.add("option-b");
                break;
            case 2:
                button.classList.add("option-c");
                break;
            case 3:
                button.classList.add("option-d");
                break;
            default:
                break;
        }

        button.style.fontSize = "18px";
        optionsContainer.appendChild(button);
    });


  nextButton.style.display = "none"; // Hide the "Next" button initially
}

// Select global audio elements
const correctSound = document.getElementById("correct-sound");
const incorrectSound = document.getElementById("incorrect-sound");
let musicSound = new Audio('http://localhost/terminal-D-Silent-Partner.mp3'); // Replace 'path/to/music.mp3' with your actual music file path
musicSound.loop = true;
musicSound.play();          
          
           // Set the default volume level to 15%
musicSound.volume = 0.15; // 0.15 represents 15%
          
            // Set the default volume level to 25%
correctSound.volume = 0.25; // 0.25 represents 25%
          
            // Set the default volume level to 25%
incorrectSound.volume = 0.25; // 0.25 represents 25%
          
       
// Function to play music for 7 seconds
function playMusicFor7Seconds() {
    musicSound.play();
    setTimeout(function() {
        musicSound.pause();
        musicSound.currentTime = 0;
    }, 9900000); // 7000 milliseconds = 7 seconds
}

// Function to handle option selection
function selectOption(selectedIndex, isCorrect) {
   // Play music for 7 seconds
    playMusicFor7Seconds();

    if (questionAnswered) {
        return; // Do nothing if the question has already been answered
    }

    questionAnswered = true;

    const current = questions[currentQuestion];
    const optionButtons = document.querySelectorAll('#options-container button');

    if (isCorrect) {
        score++;
        correctFeedback.style.display = 'block';
        optionButtons[selectedIndex].style.backgroundColor = '#3CB371';
        correctSound.play(); // Play correct sound
    } else {
        wrongAnswers.push(current);
        incorrectFeedback.style.display = 'block';
        optionButtons[selectedIndex].style.backgroundColor = '#FF6961';
        incorrectSound.play(); // Play incorrect sound
    }

 

    // Show the "Next" button after selecting an option
    nextButton.style.display = 'block';

    // Disable all answer buttons to prevent further selections
    optionButtons.forEach(button => {
        button.disabled = true;
    });

    optionButtons[selectedIndex].classList.add('selected-option');
}

nextButton.addEventListener('click', () => {
  correctFeedback.style.display = 'none';
  incorrectFeedback.style.display = 'none';
  loadNextQuestion();
});

function loadNextQuestion() {
  currentQuestion++;

  if (currentQuestion < questions.length) {
    questionAnswered = false;
    loadQuestion();
  } else {
    document.getElementById("try-again-container").style.display = "none";
    document.getElementById("quick-revision-container").style.display = "none";
    document.getElementById("question-container").style.display = "none";
    document.getElementById("options-container").style.display = "none";
    messageContainer.style.display = 'none';
    submitQuizButton.style.display = 'block';
    submitQuizButton.style.margin = '0 auto';
    submitQuizButton.style.fontWeight = 'bold';
    nextButton.style.display = 'none'; // Hide the "Next" button when "Submit" button is displayed
  }
}

submitQuizButton.addEventListener('click', () => {
    // Hide submit button and show message container
    submitQuizButton.style.display = 'none';
    messageContainer.style.display = 'block';

   
    // After 7 seconds, hide message container and show results
    setTimeout(() => {
        messageContainer.style.display = 'none';
        showResult();
    }, 7000);
});

          
   function showResult() {
                const quizContainer = document.getElementById("quiz-container");
                quizContainer.style.display = "none";

                resultContainer.innerHTML = "";

                resultContainer.style.display = "block";

                const resultText = document.createElement("h2");
                resultText.textContent = "Results";
                resultContainer.appendChild(resultText);

                // Check for a perfect score and set the message
                if (score === questions.length) {
                    congratulationsText.textContent = "Congratulations! Keep It Up!";
                  	congratulationsText.style.color = "#D4AC0D";
                  	congratulationsText.style.fontWeight = "bold";
                    resultContainer.appendChild(congratulationsText);
                }
              
              	// Show the "Quick Revision" button
    const quickRevisionContainer = document.getElementById("quick-revision-container");
    quickRevisionContainer.style.display = "block";

const grading = {
    0: "<span style='color: #c0392b; font-weight: bold;'>Every expert driver was once a beginner. Stay focused and try again! 🚦 😔</span>",
    1: "<span style='color: #c0392b; font-weight: bold;'>Every expert driver was once a beginner. Stay focused and try again! 🚦 😔</span>",
    2: "<span style='color: #c0392b; font-weight: bold;'>Every expert driver was once a beginner. Stay focused and try again! 🚦 😔</span>",
    3: "<span style='color: #c0392b; font-weight: bold;'>Every expert driver was once a beginner. Stay focused and try again! 🚦 😔</span>",
    4: "<span style='color: #c0392b; font-weight: bold;'>You've taken the first step, like learning to start the engine. Keep going! 🔑 😕</span>",
    5: "<span style='color: #c0392b; font-weight: bold;'>You've taken the first step, like learning to start the engine. Keep going! 🔑 😕</span>",
    6: "<span style='color: #c0392b; font-weight: bold;'>You've taken the first step, like learning to start the engine. Keep going! 🔑 😕</span>",
    7: "<span style='color: #c0392b; font-weight: bold;'>You've taken the first step, like learning to start the engine. Keep going! 🔑 😕</span>",
    8: "<span style='color: #c0392b; font-weight: bold;'>You're moving at a safe speed, but there's more road ahead. Keep learning! 🚗 🙁</span>",
    9: "<span style='color: #c0392b; font-weight: bold;'>You're moving at a safe speed, but there's more road ahead. Keep learning! 🚗 🙁</span>",
    10: "<span style='color: #c0392b; font-weight: bold;'>You're moving at a safe speed, but there's more road ahead. Keep learning! 🚗 🙁</span>",
    11: "<span style='color: #c0392b; font-weight: bold;'>You're moving at a safe speed, but there's more road ahead. Keep learning! 🚗 🙁</span>",
    12: "<span style='color: #c0392b; font-weight: bold;'>Your journey has begun! Like navigating your first roundabout, stay confident. 🔄 😟</span>",
    13: "<span style='color: #c0392b; font-weight: bold;'>Your journey has begun! Like navigating your first roundabout, stay confident. 🔄 😟</span>",
    14: "<span style='color: #c0392b; font-weight: bold;'>Your journey has begun! Like navigating your first roundabout, stay confident. 🔄 😟</span>",
    15: "<span style='color: #d35400; font-weight: bold;'>Your journey has begun! Like navigating your first roundabout, stay confident. 🔄 😟</span>",
    16: "<span style='color: #d35400; font-weight: bold;'>You're gaining momentum, like cruising through traffic. Keep it steady! 🚙 😐</span>",
    17: "<span style='color: #d35400; font-weight: bold;'>You're gaining momentum, like cruising through traffic. Keep it steady! 🚙 😐</span>",
    18: "<span style='color: #d35400; font-weight: bold;'>You're gaining momentum, like cruising through traffic. Keep it steady! 🚙 😐</span>",
    19: "<span style='color: #d35400; font-weight: bold;'>You're gaining momentum, like cruising through traffic. Keep it steady! 🚙 😐</span>",
    20: "<span style='color: #d35400; font-weight: bold;'>You're halfway there, like reaching the halfway point on a long drive. Keep it up! 🚘 🙂</span>",
    21: "<span style='color: #d35400; font-weight: bold;'>You're halfway there, like reaching the halfway point on a long drive. Keep it up! 🚘 🙂</span>",
    22: "<span style='color: #d35400; font-weight: bold;'>You're halfway there, like reaching the halfway point on a long drive. Keep it up! 🚘 🙂</span>",
    23: "<span style='color: #d35400; font-weight: bold;'>You're halfway there, like reaching the halfway point on a long drive. Keep it up! 🚘 🙂</span>",
    24: "<span style='color: #d35400; font-weight: bold;'>You're driving with precision, like overtaking safely on the highway. Excellent! 🚛 😄</span>",
    25: "<span style='color: #d35400; font-weight: bold;'>You're driving with precision, like overtaking safely on the highway. Excellent! 🚛 😄</span>",
    26: "<span style='color: #d35400; font-weight: bold;'>You're driving with precision, like overtaking safely on the highway. Excellent! 🚛 😄</span>",
    27: "<span style='color: #d35400; font-weight: bold;'>You're driving with precision, like overtaking safely on the highway. Excellent! 🚛 😄</span>",
    28: "<span style='color: #d35400; font-weight: bold;'>You're showing great skill, like mastering reverse parking. Impressive! 🅿️ 😁</span>",
    29: "<span style='color: #d35400; font-weight: bold;'>You're showing great skill, like mastering reverse parking. Impressive! 🅿️ 😁</span>",
    30: "<span style='color: #228B22; font-weight: bold;'>You're showing great skill, like mastering reverse parking. Impressive! 🅿️ 😁</span>",
    31: "<span style='color: #228B22; font-weight: bold;'>You're showing great skill, like mastering reverse parking. Impressive! 🅿️ 😁</span>",
    32: "<span style='color: #228B22; font-weight: bold;'>You're close to perfect, like navigating a busy intersection with ease. Outstanding! 🛑 😁 👏 👏</span>",
    33: "<span style='color: #228B22; font-weight: bold;'>You're close to perfect, like navigating a busy intersection with ease. Outstanding! 🛑 😁 👏 👏</span>",
    34: "<span style='color: #228B22; font-weight: bold;'>You're close to perfect, like navigating a busy intersection with ease. Outstanding! 🛑 😁 👏 👏</span>",
    35: "<span style='color: #228B22; font-weight: bold;'>You're close to perfect, like navigating a busy intersection with ease. Outstanding! 🛑 😁 👏 👏</span>",
    36: "<span style='color: #228B22; font-weight: bold;'>You're almost there, like seeing the destination board at a traffic checkpoint. Superb! 🏁 😁 👏 👏 👏</span>",
    37: "<span style='color: #228B22; font-weight: bold;'>You're almost there, like seeing the destination board at a traffic checkpoint. Superb! 🏁 😁 👏 👏 👏</span>",
    38: "<span style='color: #228B22; font-weight: bold;'>You're almost there, like seeing the destination board at a traffic checkpoint. Superb! 🏁 😁 👏 👏 👏</span>",
    39: "<span style='color: #228B22; font-weight: bold;'>You're almost there, like seeing the destination board at a traffic checkpoint. Superb! 🏁 😁 👏 👏 👏</span>",
    40: "<span style='color: #1abc9c; font-weight: bold;'>Perfect score! You're a true roadmaster, ready to navigate Ghana's highways with excellence. Well Done! 🚦 👌 😁 👏 👏 👏 👏 🕺 💃</span>"
};


           // Display the score
const totalQuestions = questions.length; // Total number of questions
const percentageScore = Math.round((score / totalQuestions) * 100); // Calculate percentage and round

scoreText.innerHTML = `Score: ${score}/${totalQuestions} = ${percentageScore}%`;
scoreText.style.fontWeight = "bold";

if (score > 29) {
    scoreText.style.color = "#4CAF50"; // Green for high scores
} else if (score >= 15) {
    scoreText.style.color = "#FF9800"; // Orange for medium scores
} else {
    scoreText.style.color = "#F44336"; // Red for low scores
}

resultContainer.appendChild(scoreText);

     
                const remarksText = document.createElement("p");
                remarksText.id = "remarks";
                remarksText.innerHTML = `${grading[score] || "Invalid Score"}`;
                remarksText.style.fontSize = "19px";
                remarksText.style.color = "#333";
                resultContainer.appendChild(remarksText);

                if (wrongAnswers.length > 0) {
                    const wrongAnswersText = document.createElement("p");
                    if (wrongAnswers.length === 1) {
                        wrongAnswersText.textContent = "Wrongly Answered Question:";
                    } else {
                        wrongAnswersText.textContent = "Wrongly Answered Questions:";
                    }
                    wrongAnswersText.style.fontWeight = "bold";
                    wrongAnswersText.style.fontSize = "17px";
                    wrongAnswersText.style.marginBottom = "7px";
                    resultContainer.appendChild(wrongAnswersText);

                    const wrongAnswersList = document.createElement("div");
                    wrongAnswersList.classList.add("wrong-answers-list");

                    wrongAnswers.forEach((question, index) => {
                        const originalQuestionNumber = question.number;
                        const questionText = question.question;
                        const generatedQuestionNumber = index + 1;
                        const answerItem = document.createElement("p");
                        answerItem.style.marginBottom = "17px";
                        answerItem.innerHTML = `<span class='wrong-question-number'>${originalQuestionNumber}.</span> ${questionText}`;

                        wrongAnswersList.appendChild(answerItem);
                    });

                    resultContainer.appendChild(wrongAnswersList);

                    // Show the "Try Again" button if there are wrong answers
                    const tryAgainContainer = document.getElementById("try-again-container");
                    tryAgainContainer.style.display = "block";
                }
            }
// Initial call to load the first question
loadQuestion();
          
          document.addEventListener('DOMContentLoaded', function () {
    // Get the audio elements and the mute toggle button
    var correctSound = document.getElementById('correct-sound');
    var incorrectSound = document.getElementById('incorrect-sound');
    var muteToggleButton = document.getElementById('mute-toggle');

    // Function to toggle mute/unmute
    function toggleMute() {
        var isMuted = correctSound.muted; // Check the current mute state

        // Toggle mute state for both sounds
        correctSound.muted = !isMuted;
        incorrectSound.muted = !isMuted;

        // Update button text based on the new state
        muteToggleButton.textContent = isMuted ? 'Sound-OFF🔇' : 'Sound-ON🔊';
    }

    // Add event listener to the mute toggle button
    muteToggleButton.addEventListener('click', toggleMute);
});
           // Toggle mute/unmute functionality
  const muteToggleButton = document.getElementById('mute-toggle-button');
  muteToggleButton.addEventListener('click', () => {
    if (musicSound.muted) {
      musicSound.muted = false;
      muteToggleButton.textContent = 'Music-OFF🔇';
    } else {
      musicSound.muted = true;
      muteToggleButton.textContent = 'Music-ON🔊';
    }
  });
          
           // Disable right-click
  document.addEventListener('contextmenu', function(e) {
    e.preventDefault();
  });

  // Disable common keyboard shortcuts
  document.addEventListener('keydown', function(e) {
    if (e.ctrlKey && (e.key === 'u' || e.key === 's' || e.key === 'c' || e.key === 'p')) {
      e.preventDefault();
    }
    if (e.key === 'F12' || (e.ctrlKey && e.shiftKey && (e.key === 'I' || e.key === 'J'))) {
      e.preventDefault();
    }
  });
              
        </script>