Guest User

Untitled

a guest
Oct 20th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. function generateRandomNumber(array, maxN) {
  2. let randomN = Math.floor(Math.random() * maxN) + 0;
  3. console.log(array.length);
  4. console.log(maxN);
  5.  
  6. if(array.length == maxN) {
  7. array.length = 0;
  8. }
  9.  
  10. if(!array.includes(randomN)) {
  11. array.push(randomN);
  12. }
  13. else {
  14. randomN = generateRandomNumber(array, maxN);
  15. }
  16. return randomN;
  17. }
  18.  
  19.  
  20. var array = [];
  21.  
  22. $("div").on('click', function(){
  23. console.log('clicked');
  24. generateRandomNumber(array, 10);
  25. })
  26.  
  27. var array = [];
  28.  
  29. $("div").on('click', function(){
  30. console.log('clicked');
  31. generateRandomNumber(array, 10);
  32. console.log(array);
  33. })
Add Comment
Please, Sign In to add comment