GoConqr has a new look! Let us know what you think.

Module 7 of 10 · Media

Create a lottery

Kostas Diakogiannis

Create a lottery

M-3 Create a Lottery

Create a lottery that creates a  random number from 1 to 100. This is the lucky number.

Create a random number from 1 to 100 for the user. This is users number.

If the user's number is the lucky number then the user wins 100$.

If the absolute difference between user's number and the lucky number is less or equal to ten, then the user wins 100$ minus 10$ for every number in between. 

Example: The lucky numbers is 85 and the usersNumber is 77. The absolute difference is 8, so the user wins 20$ (100 - 8 * 10). If the usersNumber is 84, the user wins 90$ and so on.

In any other case the user wins nothing.

Print the lucky number, the user's number and the winnings of the user. 

Extra bonus: Run this lottery 100 times and calculate how much money have you given to winnings.

Instructions

You must submit an attempt for this quiz to progress. You can submit it after the last question.

Go to the chosen module

Feedback

What is it about?

What do you think of the new look?

How do you like it?