0

So, I have an array and I want to get one random value out of it, however, only one, in the following code, it prints out in the screen all the values inside, it can also contain jQuery, I appreciate any sort of help, thanks !

var fruits = ["Banana", "Orange", "Apple", "Mango"];

function sortear() {
  var random = fruits[Math.floor(Math.random() * fruits.length)];
  document.getElementById("p").innerHTML = fruits;
}
<button id="click" onclick="sortear()">CLICK</button>
<p id="p"></p>
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339

0 Answers0