
<html lang="en">
<head>
    <meta charset="UTF-8"></meta>
    <meta content="width=device-width, initial-scale=1.0" name="viewport"></meta>
    <title>Grade 8, Mathematics, Number Patterns Worksheet (Lesson 1)</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;
}

.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: 'Find the 20th term of the pattern 2, 4, 6, 8, ...', answer: '40' },
    { question: 'Which term is 99 in the pattern 1, 3, 5, 7, ...?', answer: '50' },
    { question: 'Write the first 5 terms of the pattern 2n - 1.', answer: '1, 3, 5, 7, 9' },
    { question: 'Is 88 a term of the pattern 2, 4, 6, 8, ...?', answer: 'Yes' },
    { question: 'Find the 12th term of the odd number pattern starting from 1.', answer: '23' },

    { question: 'Find the 13th term of the pattern 5, 10, 15, 20, ...', answer: '65' },
    { question: 'Which term is 54 in the pattern 6, 12, 18, 24, ...?', answer: '9' },
    { question: 'Write the general term for the pattern 4, 8, 12, 16, ...', answer: '4n' },
    { question: 'Is 125 a term in the pattern 5, 10, 15, 20, ...?', answer: 'Yes' },
    { question: 'What is the 18th term of the multiples of 7 pattern?', answer: '126' },

    { question: 'Write the first 5 prime numbers starting from 2.', answer: '2, 3, 5, 7, 11' },
    { question: 'What is the 6th term of the prime number pattern?', answer: '13' },
    { question: 'Is 51 a prime number?', answer: 'No' },
    { question: 'Write the general rule for identifying a prime number.', answer: 'A number greater than 1, divisible only by 1 and itself' },
    { question: 'Find the sum of the first 4 prime numbers.', answer: '17' },

    { question: 'What is the 8th term of the square number pattern 1, 4, 9, ...?', answer: '64' },
    { question: 'Which term is 81 in the square number pattern?', answer: '9' },
    { question: 'Is 50 a square number?', answer: 'No' },
    { question: 'What is the 12th term in the square number pattern?', answer: '144' },

    { question: 'What is the 7th term of the triangular number pattern?', answer: '28' },
    { question: 'Which term is 45 in the triangular number pattern?', answer: '9' },
    { question: 'Write the general term for the triangular number pattern.', answer: 'n(n + 1)/2' },
    { question: 'Is 50 a triangular number?', answer: 'No' },
    { question: 'What is the 10th term of the triangular number pattern?', answer: '55' },

    { question: 'What is the 5th term of the pattern 2, 4, 8, 16, ...?', answer: '32' },
    { question: 'Write the first 5 terms of the pattern 2n<sup>2</sup> - 1.', answer: '1, 7, 17, 31, 49' },
    { question: 'Which term is 49 in the pattern n<sup>2</sup> - n?', answer: '8' },
    { question: 'Find the 6th term of the pattern 5n + 3.', answer: '33' },

    { question: 'Write the nth term of the pattern 2, 6, 12, 20, ...', answer: 'n(n + 1)' },
    { question: 'What is the 50th term of the pattern n<sup>2</sup> + 2?', answer: '2502' },
    { question: 'Which term is 98 in the pattern 2n<sup>2</sup> + 2n?', answer: '7' },
    { question: 'Find the 25th term of the pattern n<sup>3</sup>.', answer: '15625' },
    { question: 'What is the 8th term of the pattern 3n<sup>2</sup> - n?', answer: '184' },

    { question: 'Find the missing term: 2, 4, 8, 16, ___, 64.', answer: '32' },
    { question: 'What is the next term in the pattern 1, 4, 9, 16, 25, ...?', answer: '36' },
    { question: 'Complete the pattern: 1, 3, 6, 10, ___, 21.', answer: '15' },
    { question: 'Which term is 128 in the pattern 2<sup>n</sup>?', answer: '7' },
    { question: 'Find the sum of the first 4 terms in the pattern 2, 4, 8, 16, ...', answer: '30' },

    { question: 'What is the smallest multiple of 3 larger than 100?', answer: '102' },
    { question: 'Write the first 5 terms of the pattern n<sup>3</sup> - n.', answer: '0, 6, 24, 60, 120' },
    { question: 'Is 144 a term in the square number pattern?', answer: 'Yes' },
    { question: 'Find the 15th term of the multiples of 11.', answer: '165' },
    { question: 'What is the 20th term of the pattern 5n + 2?', answer: '102' },
    { question: 'Which term is 72 in the pattern 6n?', answer: '12' },
    { question: 'Write the general term for the multiples of 13.', answer: '13n' },
    { question: 'Is 243 a term in the pattern 3<sup>n</sup>?', answer: 'Yes' },
    { question: 'What is the 12th term of the pattern n<sup>2</sup> + n?', answer: '156' }
];


        // 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: Type the correct answer</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 8, Mathematics, Number Patterns Worksheet (Lesson 1)</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>
