Party game example
function startNewGame(gameType) {
return new Promise((resolve, reject) => {
if (gameType === 'trivia') {
console.log('Starting a new trivia game...');
// simulate game setup with a 2 second delay
setTimeout(() => {
resolve();
}, 2000);
} else if (gameType === 'charades') {
console.log('Starting a new charades game...');
// simulate game setup with a 2 second delay
setTimeout(() => {
resolve();
}, 2000);
} else {
reject(new Error('Invalid game type'));
}
});
}
startNewGame('trivia')
.then(() => {
console.log('Trivia game started successfully!');
})
.catch((error) => {
console.log(error.message);
});Last updated