Untitled
unknown
plain_text
a month ago
888 B
2
Indexable
Never
javascript Copy // Define variables for the game let score = 0; let totalQuestions = 0; // Function to generate random math problems function generateMathProblem() { // Generate random numbers and an operator (+, -, *, /) let num1 = Math.floor(Math.random() * 10) + 1; let num2 = Math.floor(Math.random() * 10) + 1; let operators = ['+', '-', '*', '/']; let operator = operators[Math.floor(Math.random() * operators.length)]; // Create the math problem string let problem = `${num1} ${operator} ${num2}`; // Calculate the correct answer let correctAnswer = eval(problem); return { problem, correctAnswer }; } // Function to check the user's answer function checkAnswer(userAnswer, correctAnswer) { if (parseFloat(userAnswer) === correctAnswer) { score++; console.log("Correct! Your score is: " + score); ...
Leave a Comment