mardi 18 juillet 2017

Javascript Random and Floor Math

Hi I am having trouble with this assignment for my online class. No one is online to help me.

Make a function that takes a number of quarters (1 quarter = 1 game).

There is a 1 in 100 chance to win the slot machine (which will give you between 50 - 100 quarters -- use Math.random and Math.floor to pick a random number of coins).

While the user still has quarters, use Math.random to determine if they won.

If they ever win, return the number of quarters (ex: they had 50 remaining quarters and won 90, so it should return 140).

Return 0 if all the quarters were wasted.

Bonus (Only If You Have Time):

Let the user pass the number they are willing to leave with (ex: If they won the lottery and still have 40 coins, they will keep playing until they have collected 200 coins)~

I got this so far but it says undefined.

var quarter = 1;

function game() {
 Math.floor(Math.random(quarter)*50)+51;

 if (quarter > 1) {
   (Math.random(quarter) * 100)
 }
}

game();




Aucun commentaire:

Enregistrer un commentaire