Created
February 28, 2024 04:36
-
-
Save ankitbtanna/3fcff4a0e1f93404c101f3e32af8a03d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const readline = require('readline'); | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
function generateRandomNumber(min, max) { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} | |
function generateGame() { | |
const game = { | |
numbers: [], | |
powerball: generateRandomNumber(1, 20) | |
}; | |
while (game.numbers.length < 7) { | |
const randomNumber = generateRandomNumber(1, 35); | |
if (!game.numbers.includes(randomNumber)) { | |
game.numbers.push(randomNumber); | |
} | |
} | |
return game; | |
} | |
rl.question('Enter the number of games (between 1 and 18): ', (numGames) => { | |
numGames = parseInt(numGames); | |
if (numGames < 1 || numGames > 18 || isNaN(numGames)) { | |
console.log('Error: Please enter a number between 1 and 18.'); | |
rl.close(); | |
return; | |
} | |
const games = []; | |
for (let i = 0; i < numGames; i++) { | |
games.push(generateGame()); | |
} | |
console.log('Generated Games:'); | |
games.forEach((game, index) => { | |
console.log(`Game ${index + 1}: ${game.numbers.join(', ')} Powerball: ${game.powerball}`); | |
}); | |
rl.close(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment