Facebook
From Social Leopard, 6 Years ago, written in JavaScript.
Embed
Download Paste or View Raw
Hits: 291
  1. //I'm downloading a button from the page
  2. const button = document.querySelector("button");
  3.  
  4. //Create arrays
  5. const result = []
  6.  
  7. //Random function
  8. const random = function() {
  9.  
  10.     if (result.length === 6) return;
  11.     const div = document.createElement("div"); //Create element
  12.     const score = Math.floor (Math.random() * 49 + 1);
  13.  
  14.     for (let i = 0; i < result.length; i++) {
  15.         if (score === result[i]) {
  16.             return random();
  17.         }
  18.     }
  19.  
  20.     div.textContent = score; //Value of the content
  21.     document.body.appendChild(div); //Add element
  22.  
  23.     result.push(score);
  24. }
  25.  
  26.  
  27.  
  28. button.addEventListener("click",random); //Waiting for a button click
  29.