JavaScipt code for Game with checkanswer and start game button then when pressed it start and you get timed and when it hits 10 minutes you get kicked out but you have 5 questions and at the end it shows your grade

1 answer

Here is a basic implementation of a game in JavaScript that includes a check answer function, a start game button, a time limit of 10 minutes, 5 questions, and a grading system at the end.

```html
<!DOCTYPE html>
<html>
<head>
<title>Game</title>
</head>
<body>
<h1>Welcome to the Game!</h1>
<p>Answer the following questions:</p>

<div id="question"></div>
<input type="text" id="answer">
<button onclick="checkAnswer()">Submit Answer</button>
<button onclick="startGame()">Start Game</button>

<p id="status"></p>

<script>
let currentQuestion = 0;
let correctAnswers = 0;
let questions = [
{question: "What is 2 + 2?", answer: "4"},
{question: "What is the capital of France?", answer: "Paris"},
{question: "What is the largest planet in our solar system?", answer: "Jupiter"},
{question: "What is the powerhouse of the cell?", answer: "Mitochondria"},
{question: "What is the opposite of up?", answer: "Down"}
];

function checkAnswer() {
let answer = document.getElementById("answer").value;
if (answer.toLowerCase() === questions[currentQuestion].answer.toLowerCase()) {
correctAnswers++;
}
currentQuestion++;
if (currentQuestion < questions.length) {
displayQuestion();
} else {
endGame();
}
}

function startGame() {
currentQuestion = 0;
correctAnswers = 0;
displayQuestion();
setTimeout(endGame, 600000); // 10 minutes (10 * 60 * 1000 milliseconds)
}

function displayQuestion() {
document.getElementById("question").innerHTML = questions[currentQuestion].question;
document.getElementById("answer").value = "";
}

function endGame() {
let grade = Math.round((correctAnswers / questions.length) * 100);
document.getElementById("status").innerHTML = `Game Over! Your grade is ${grade}%`;
}
</script>
</body>
</html>
```

In this game, the user can answer each question by typing their response in the input field and clicking the "Submit Answer" button. The correct answers will be automatically compared to the predefined answers in the `questions` array. The user can start the game by clicking the "Start Game" button, which triggers the `startGame()` function. The game has a time limit of 10 minutes, after which the `endGame()` function is called to display the user's grade based on the number of correct answers.