jeudi 22 février 2018

Fact Generator (Not Random)

I'm adding a random fact generator to my company's about page. It currently looks like this:

JS:

 <script>var targetemployee = document.getElementById('targetemployee');
var factsemployee = [

  'Fact1',
  'Fact2',
  'Fact3',
  'Fact4',
  'Fact5',
];
function newEmployeeFact () {
  var i = Math.floor(Math.random() * factsemployee.length) | 0;
  targetemployee.innerText = factsemployee[i]

}

newEmployeeFact();

</script>

HTML:

<p class="funfact" id="targetemployee"></p><button type="button" class="hover-shadow" style="text-align: middle; font-size: 0.8em; bottom: 0px" onclick="newEmployeeFact()"> NEW FACT </button>

</div>

My problem is that after clicking it a few times, it will sometimes show the same fact instead of a new one so I just want to change is so that it's sequential. Any tips? I'm a JS beginner so I appreciate y'all's help!




Aucun commentaire:

Enregistrer un commentaire