lundi 11 septembre 2017

How do I create a random name generator with specific time restriction so name doesn't come up again right away?

Using HTML/JavaScript: How do I create a random name generator with 4-5 months restriction. So ones a name is selected/used... it does not repeat for another 4 months.

So lets say if we randomly selected "Joe" on August 1st, 2017. His name should not repopulate again until January 1st, 2018. The reason is because we have about 25 names currently, and ones a week (on average 4 times a month) we randomly select a name. (ideally we would like all 25 people to be selected at least once so they all can win free lunch :D )

the monthly restriction is where i am completely lost as showed in current code we do have just the name generator.

Thanks for your time and assistance!!

Below is my working codes so far...

<!DOCTYPE html>
<html >
<head>
  <meta charset="UTF-8">
  <title>And the WINNER is...</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>
  <h1>And the WINNER is...</h1>

<FORM NAME="WordForm">  
<INPUT TYPE=TEXT NAME="WordBox" id="wordbox"><BR>
<INPUT TYPE=BUTTON VALUE="Generate" onClick="PickRandomWord(document.WordForm);" id="button">
</FORM>
  
   <script>
   var NumberOfWords = 5  // usally there are 25 here

var words = new BuildArray(NumberOfWords)

// Use the following variables to 
// define your random words:
words[1] = "namehere1"
words[2] = "namehere2"
words[3] = "namehere3"
words[4] = "namehere4"
words[5] = "namehere5"


function BuildArray(size){
this.length = size
for (var i = 1; i <= size; i++){
this[i] = null}
return this
}

function PickRandomWord(frm) {
// Generate a random number between 1 and NumberOfWords
var rnd = Math.ceil(Math.random() * NumberOfWords)

// Display the word inside the text box
frm.WordBox.value = words[rnd]
}
 </script>
<h3>  (Above once the name is generated, it should not show up again for next 4 months is what i am trying to do) </h3>
<h4> Thanks! </h4>
</body>
</html>



Aucun commentaire:

Enregistrer un commentaire