
<html lang="en">
<head>
    <meta charset="UTF-8"></meta>
    <meta content="width=device-width, initial-scale=1.0" name="viewport"></meta>
    <title>Grade 2, Mathematics, Learning the 2 Multiplication Table, worksheet</title>
    <style>
        h1 {
            font-size: 24px;
            color: green;
        }
        .correct {
            color: green;
        }
        .wrong {
            color: red;
        }
        body, html {
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
            font-family: Arial, sans-serif;
        }
        h1 {
            text-align: left;
            font-size: 24px;
            margin-top: 20px;
        }
        label {
            font-size: 20px;
        }
        p {
            font-size: 20px;
        }
.question {
    margin-bottom: 15px;
    font-size: 20px;
    color: blue;
}

.question label {
    display: block;
    margin-bottom: 5px;
}

.question input[type="text"] {
    width: 80%; /* Increased width */
    max-width: 300px; /* For larger screens, increase max-width */
    text-align: left;
    margin-bottom: 10px;
    font-size: 20px;
}

.question .answer-display {
    font-size: 20px;
    margin-top: 5px;
}
        .exercise-instructions {
            font-size: 20px;
            margin-bottom: 20px;
            font-weight: bold;
        }
        .buttons {
            margin-top: 20px;
            text-align: center;
        }
        .buttons button {
            font-size: 18px;
            padding: 10px 20px;
            margin: 5px;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }
        .check-button {
            background-color: #4CAF50;
        }
        .retry-button {
            background-color: #f44336;
        }
        .marks {
            color: blue;
            font-size: 20px;
            font-weight: bold;
        }
@media (max-width: 300px) {
    .question input[type="text"] {
        max-width: 70%; /* Keep this for smaller screens */
    }
}
    </style>
    <script>
        document.addEventListener('contextmenu', event => event.preventDefault());

        document.addEventListener('keydown', event => {
            if (event.key === "F12" || (event.ctrlKey && event.shiftKey && event.key === 'I') || (event.ctrlKey && event.shiftKey && event.key === 'J') || (event.ctrlKey && event.key === 'U')) {
                event.preventDefault();
            }
        });

        document.addEventListener('copy', event => {
            event.preventDefault();
        });

        function shuffle(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]];
            }
            return array;
        }

        const questions2 = [
    { question: '2 × 1 ', answer: '1+1' },
    { question: '2 × 2 ', answer: '2+2' },
    { question: '2 × 3 ', answer: '3+3' },
    { question: '2 × 4 ', answer: '4+4' },
    { question: '2 × 5 ', answer: '5+5' },
    { question: '2 × 6 ', answer: '6+6' },
    { question: '2 × 7 ', answer: '7+7' },
    { question: '2 × 8 ', answer: '8+8' },
    { question: '2 × 9 ', answer: '9+9' },
    { question: '2 × 10 ', answer: '10+10' },
    { question: '2 × 11 ', answer: '11+11' },
    { question: '2 × 12 ', answer: '12+12' }
];


        // Shuffle questions
        const shuffledQuestions = shuffle(questions2);

function normalizeText(text) {
    // Normalize the text: trim, lowercase, and replace multiple spaces with a single space
    // Also remove punctuation for comparison (except . , etc.)
    return text.trim()
               .toLowerCase()
               .replace(/[^\w\s,.]/g, '') // Remove unwanted punctuation, keeping . and ,.
               .replace(/\s+/g, ''); // Replace multiple spaces with a single space
}



        function displayQuestions() {


            const questionsContainer2 = document.getElementById('questionsContainer2');
            questionsContainer2.innerHTML = `
                <div class="exercise-instructions">Exercise: Answer the following questions by completing the equation,
                like these examples:<br> 
                2 × 1 = 1 + 1,<br> 
                2 × 2 = 2 + 2,<br> 
                2 × 3 = 3 + 3.</div>
            `;
            questions2.forEach((question, index) => {
                const questionHTML = `
                    <div class="question">
                        <label>${index + 1}). ${question.question} = </label>
                        <input type="text" maxlength="70" data-answer="${question.answer}">
                        <span class="answer-display"></span>
                    </div>
                `;
                questionsContainer2.innerHTML += questionHTML;
            });
        }

        function checkAnswers() {
            let score1 = 0;

            const totalQuestions1 = questions2.length;

            // Check answers for Exercise
            document.querySelectorAll('#questionsContainer2 .question').forEach((questionDiv) => {
                const input = questionDiv.querySelector('input[type="text"]');
                const feedback = questionDiv.querySelector('.answer-display');
                const correctAnswer = input.dataset.answer;

                if (normalizeText(input.value) === normalizeText(correctAnswer)) {
                    feedback.innerHTML = '<span class="correct">Correct!</span>';
                    score1++;
                } else {
                    feedback.innerHTML = `<span class="wrong">Wrong! The correct answer is: ${correctAnswer}</span>`;
                }
            });

            // Hide the "Check Answers" button after checking the answers
            document.getElementById('checkAnswersButton').style.display = 'none';

            // Calculate total score and percentage
            const percentage = (score1 / totalQuestions1) * 100;

            // Display total results
            const resultText = `
                <div class="marks">Exercise Score: ${score1}/${totalQuestions1}</div>
                <div class="marks"><strong>Total Score: ${score1}/${totalQuestions1} (${percentage.toFixed(2)}%)</strong></div>
                <div>${getGradeFeedback(percentage)}</div>
                ${percentage === 100 ? '<div class="result-images"><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2-ubMp9uAa6YdIe_kBJ5KHLm9lvzYdypfXpvij7BtmhFONiFt9j3D7r1V_M4wPnIkIsocug7NzEHIYr35z4J8KqsKIXqw2YCpi_HY6C3OiGkC9ADz9Ee2ne-gO0VgladOU5r5FbSk2jrIy8rdgM0G895UGG_ayI0Bkeh1CU5ZswyoeWQyHsaICeB6Z7k/s1600/star.jpg" alt="Star"><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQ6tyya1xafjBJ3poGtUE9T5Tj-YAnRsc1SnByb_1pebaR-LBVZYtBJyZ2y_0BMix1y5byTXw2FDWyRzK7_6gAq3duQofJEibkjoQYhCQ-qGcisr9uR6jJ2IN0P510osrhyphenhyphencjOEYoC9uuYnnnL6L61GTgAoWhtcUHu2sXs5RTwaLZAsIwGlePDW-ZXBb8/s1600/happy%20face.jpg" alt="Happy Face"></div>' : ''}
            `;
            document.getElementById('result').innerHTML = resultText;
            document.getElementById('result').style.fontSize = '20px';
            document.getElementById('result').style.fontWeight = 'bold';
            document.querySelectorAll('.marks').forEach(element => {
                element.style.color = 'blue';
            });
        }

        function getGradeFeedback(percentage) {
            if (percentage <= 25) {
                return 'Keep trying, you are improving! Keep up the effort!';
            } else if (percentage <= 50) {
                return 'Good job! You are doing well, keep practicing!';
            } else if (percentage <= 75) {
                return 'Great work! You are almost there, keep it up!';
            } else if (percentage <= 85) {
                return 'Excellent! You are doing fantastic!';
            } else if (percentage <= 99) {
                return 'Almost perfect! Keep up the great work!';
            } else {
                return 'Perfect score! You did an amazing job!';
            }
        }

        window.onload = function() {
            displayQuestions();

            document.getElementById('checkAnswersButton').addEventListener('click', checkAnswers);
            document.getElementById('retryButton').addEventListener('click', () => {
                location.reload(); // This will refresh the page
            });
        }
    </script>
</head>
<body>
    <h1>Grade 2, Mathematics, Learning the 2 Multiplication Table, worksheet</h1>
    <div id="questionsContainer2"></div>
    <div id="result"></div>
    <div class="buttons">
        <button class="check-button" id="checkAnswersButton">Check Answers</button>
        <button class="retry-button" id="retryButton">Retry</button>
    </div>
</body>
</html>
