mercredi 24 février 2016

Javascript - How do I make a button generate a random integer from 1-12, and have the button constantly produce that same number

So using Javascript, I am trying to make a button generate a random number from 1-12, and have that button generate that same number until I refresh the page. For example, if I click a button and it randomly generates 7, I want that button to continually produce a value of 7. When I reload the page and click the button, I want it to generate another random number from 1-12, and hold that value.

All I got is:

$("#buttonGreen").click(function() {
  $("#scoreNum").html((Math.floor(Math.random() * 12) + 1));
});

but this will generate a different random number between 1-12 every time I click it.




Aucun commentaire:

Enregistrer un commentaire