Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Challenge (lottery) | Functions
Introduction to TypeScript

Challenge (lottery)Challenge (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!

1. You can go two ways to solve this task. You can use an if statement or a switch statement.
2. If you choose to use a switch statement, you need to define cases for each winning option, or you can define cases for winning options and handle losing options in the default case.
3. If you choose to use an if statement, you need to specify the action for the winning scenario, which is when peek is equal to 2 or 7. Leave the losing scenarios for the else block.
4. Write your function and run it; the code will automatically generate a random number between 0 and 9 and use your function.

Все було зрозуміло?

Секція 5. Розділ 3
course content

Зміст курсу

Introduction to TypeScript

Challenge (lottery)Challenge (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!

1. You can go two ways to solve this task. You can use an if statement or a switch statement.
2. If you choose to use a switch statement, you need to define cases for each winning option, or you can define cases for winning options and handle losing options in the default case.
3. If you choose to use an if statement, you need to specify the action for the winning scenario, which is when peek is equal to 2 or 7. Leave the losing scenarios for the else block.
4. Write your function and run it; the code will automatically generate a random number between 0 and 9 and use your function.

Все було зрозуміло?

Секція 5. Розділ 3
some-alt