Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Challenge: Lottery | Section
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Essential TypeScript Basics for JavaScript Developers - 1768407373799

bookChallenge: Lottery

Task

Gambling is bad, but it can be profitable for the casino owner and sometimes the players. However, you should only gamble with the extra money that you are willing to spend at the casino.

Your task is to write a function that determines the winner 🎉 and loser 😠 . Our lottery is very simplified, so the winner is the one who gets the number 2 or 7. There are a total of 10 options, meaning the number ranges from 0 to 9. The function should take one parameter, which is the number guessed by the player. If this number is a winning number, you should print 'Congratulations, you are now rich!' on the screen. If the number is not a winning number, then print 'Unfortunately, you lost, come back tomorrow'.

Feel free to peek at the hint or solution if you have any difficulties completing this task. We are all here to learn!

1234567
function giveATry(___) { // write your implementation here } let randomValue = Math.floor(Math.random() * 10); // peeking a random number from 0 to 9 console.log(`You got the number ${randomValue}!`) giveATry(randomValue)
copy
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 30

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

bookChallenge: Lottery

Glissez pour afficher le menu

Task

Gambling is bad, but it can be profitable for the casino owner and sometimes the players. However, you should only gamble with the extra money that you are willing to spend at the casino.

Your task is to write a function that determines the winner 🎉 and loser 😠 . Our lottery is very simplified, so the winner is the one who gets the number 2 or 7. There are a total of 10 options, meaning the number ranges from 0 to 9. The function should take one parameter, which is the number guessed by the player. If this number is a winning number, you should print 'Congratulations, you are now rich!' on the screen. If the number is not a winning number, then print 'Unfortunately, you lost, come back tomorrow'.

Feel free to peek at the hint or solution if you have any difficulties completing this task. We are all here to learn!

1234567
function giveATry(___) { // write your implementation here } let randomValue = Math.floor(Math.random() * 10); // peeking a random number from 0 to 9 console.log(`You got the number ${randomValue}!`) giveATry(randomValue)
copy
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 30
some-alt