Question
give me node.js code for my game wheel of fortune
Answers
GPT 3.5
Here is an example of a simple Wheel of Fortune game implemented in Node.js:
```javascript
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const wheel = ["$100", "$200", "$300", "$400", "$500", "Bankrupt", "Lose a Turn"];
function spinWheel() {
return wheel[Math.floor(Math.random() * wheel.length)];
}
function playGame() {
console.log("Welcome to Wheel of Fortune!");
rl.question("Press Enter to spin the wheel...", () => {
const result = spinWheel();
console.log(`You spun ${result}`);
if (result.startsWith("$")) {
console.log("Congratulations, you win " + result);
} else if (result === "Bankrupt") {
console.log("Oh no, you went bankrupt!");
} else if (result === "Lose a Turn") {
console.log("Sorry, you lose a turn");
}
rl.question("Do you want to play again? (yes/no)", (answer) => {
if (answer.toLowerCase() === "yes") {
playGame();
} else {
console.log("Thanks for playing!");
rl.close();
}
});
});
}
playGame();
```
This code sets up a simple Wheel of Fortune game where the player can spin the wheel to win different amounts of money, go bankrupt, or lose a turn. The game will prompt the player to spin the wheel, display the result, and then ask if they want to play again.
```javascript
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const wheel = ["$100", "$200", "$300", "$400", "$500", "Bankrupt", "Lose a Turn"];
function spinWheel() {
return wheel[Math.floor(Math.random() * wheel.length)];
}
function playGame() {
console.log("Welcome to Wheel of Fortune!");
rl.question("Press Enter to spin the wheel...", () => {
const result = spinWheel();
console.log(`You spun ${result}`);
if (result.startsWith("$")) {
console.log("Congratulations, you win " + result);
} else if (result === "Bankrupt") {
console.log("Oh no, you went bankrupt!");
} else if (result === "Lose a Turn") {
console.log("Sorry, you lose a turn");
}
rl.question("Do you want to play again? (yes/no)", (answer) => {
if (answer.toLowerCase() === "yes") {
playGame();
} else {
console.log("Thanks for playing!");
rl.close();
}
});
});
}
playGame();
```
This code sets up a simple Wheel of Fortune game where the player can spin the wheel to win different amounts of money, go bankrupt, or lose a turn. The game will prompt the player to spin the wheel, display the result, and then ask if they want to play again.