Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- document.write("<!DOCTYPE html>\r\n<html lang=\"en\">\r\n<head>\r\n <meta charset=\"UTF-8\">\r\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\r\n <title>CAPTCHA<\/title>\r\n <style>\r\n body {\r\n font-family: Arial, sans-serif;\r\n display: flex;\r\n justify-content: center;\r\n align-items: center;\r\n height: 100vh;\r\n margin: 0;\r\n background-color: #f4f4f4;\r\n }\r\n .container {\r\n background: #fff;\r\n padding: 20px;\r\n border-radius: 8px;\r\n box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);\r\n }\r\n #captcha-container {\r\n text-align: center;\r\n }\r\n #captcha-image {\r\n max-width: 100%;\r\n height: auto;\r\n margin: 10px 0;\r\n }\r\n #error-message {\r\n color: red;\r\n margin-top: 10px;\r\n }\r\n <\/style>\r\n <script>\r\n document.addEventListener('DOMContentLoaded', function() {\r\n const questionElement = document.getElementById('question');\r\n const answerInput = document.getElementById('answer');\r\n const submitButton = document.getElementById('submit');\r\n const errorMessage = document.getElementById('error-message');\r\n const captchaImage = document.getElementById('captcha-image');\r\n\r\n let correctAnswers = 0;\r\n const totalQuestions = 10;\r\n let currentQuestion = 0;\r\n\r\n function generateQuestion() {\r\n const num1 = Math.floor(Math.random() * 100);\r\n const num2 = Math.floor(Math.random() * 100);\r\n const operator = ['+', '-', '*', '\/'][Math.floor(Math.random() * 4)];\r\n let question, correctAnswer;\r\n\r\n switch (operator) {\r\n case '+':\r\n question = `${num1} + ${num2}`;\r\n correctAnswer = num1 + num2;\r\n break;\r\n case '-':\r\n question = `${num1} - ${num2}`;\r\n correctAnswer = num1 - num2;\r\n break;\r\n case '*':\r\n question = `${num1} * ${num2}`;\r\n correctAnswer = num1 * num2;\r\n break;\r\n case '\/':\r\n question = `${num1} \/ ${num2}`;\r\n correctAnswer = num2 !== 0 ? num1 \/ num2 : 'undefined';\r\n break;\r\n }\r\n\r\n return { question, correctAnswer };\r\n }\r\n\r\n function loadCountryQuestion() {\r\n questionElement.textContent = 'What is the result of 0\/0?';\r\n answerInput.placeholder = 'Your answer';\r\n captchaImage.style.display = 'none';\r\n }\r\n\r\n function handleSubmit() {\r\n const answer = answerInput.value.trim().toLowerCase();\r\n\r\n if (currentQuestion === 0 && answer === 'undefined') {\r\n correctAnswers++;\r\n currentQuestion++;\r\n if (correctAnswers >= totalQuestions) {\r\n alert('CAPTCHA passed!');\r\n location.reload();\r\n } else {\r\n loadMathQuestion();\r\n }\r\n } else if (currentQuestion > 0) {\r\n const { correctAnswer } = generateQuestion();\r\n if (answer === correctAnswer.toString()) {\r\n correctAnswers++;\r\n currentQuestion++;\r\n if (correctAnswers >= totalQuestions) {\r\n alert('CAPTCHA passed!');\r\n location.reload();\r\n } else {\r\n loadMathQuestion();\r\n }\r\n } else {\r\n errorMessage.textContent = 'Incorrect answer. Please try again.';\r\n }\r\n } else {\r\n errorMessage.textContent = 'Please answer the question.';\r\n }\r\n answerInput.value = '';\r\n }\r\n\r\n function loadMathQuestion() {\r\n questionElement.textContent = '';\r\n captchaImage.style.display = 'none';\r\n const { question } = generateQuestion();\r\n questionElement.textContent = `Solve: ${question}`;\r\n }\r\n\r\n \/\/ Start with the math question \"0\/0\"\r\n loadCountryQuestion();\r\n\r\n submitButton.addEventListener('click', handleSubmit);\r\n });\r\n <\/script>\r\n<\/head>\r\n<body>\r\n <div class=\"container\">\r\n <div id=\"captcha-container\">\r\n <div id=\"question\"><\/div>\r\n <img id=\"captcha-image\" src=\"\" alt=\"CAPTCHA Image\">\r\n <input type=\"text\" id=\"answer\" placeholder=\"Your answer\">\r\n <button id=\"submit\">Submit<\/button>\r\n <div id=\"error-message\"><\/div>\r\n <\/div>\r\n <\/div>\r\n<\/body>\r\n<\/html>");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement