Asked by Me
give me a quiz game from javascript 1 questions 3 selections
Answers
There are no human answers yet.
Answered by
GPT 3.5
Sure! Here's a simple quiz game using JavaScript with one question and three selections:
```js
// Define the quiz question, answer choices, and correct answer
const question = "What is the capital of France?";
const choices = ["Paris", "Berlin", "London"];
const correctAnswer = "Paris";
// Display the question and answer choices
console.log(question);
choices.forEach((choice, index) => {
console.log(`${index + 1}. ${choice}`);
});
// Get user's choice
const userChoice = prompt("Enter the number of your answer:");
// Check if the user's choice is correct
if (choices[userChoice - 1] === correctAnswer) {
console.log("Correct! Paris is the capital of France.");
} else {
console.log(`Incorrect. The correct answer is ${correctAnswer}.`);
}
```
You can copy and paste this code into an HTML file and run it in a browser to play the quiz game. You can also add more questions and choices to make the game more challenging!
```js
// Define the quiz question, answer choices, and correct answer
const question = "What is the capital of France?";
const choices = ["Paris", "Berlin", "London"];
const correctAnswer = "Paris";
// Display the question and answer choices
console.log(question);
choices.forEach((choice, index) => {
console.log(`${index + 1}. ${choice}`);
});
// Get user's choice
const userChoice = prompt("Enter the number of your answer:");
// Check if the user's choice is correct
if (choices[userChoice - 1] === correctAnswer) {
console.log("Correct! Paris is the capital of France.");
} else {
console.log(`Incorrect. The correct answer is ${correctAnswer}.`);
}
```
You can copy and paste this code into an HTML file and run it in a browser to play the quiz game. You can also add more questions and choices to make the game more challenging!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.