mercredi 20 juillet 2016

Combine random array items into sentence

What I'm trying to do is basically take the below code and make it work so that I can combine items from several arrays into one sentence. So for instance, right now if I run this code it will give me random items from myarray, i.e. item1, 2, etc. But what I would like to do is create several arrays and have the result be a sentence which includes (in this order) random items from array1, array2, array3, etc. Basically a random sentence generator using arrays.

 function GetValue()
{
var myarray= new Array("item1","item2","item3");
var random = myarray[Math.floor(Math.random() * myarray.length)];
document.getElementById("message").innerHTML=random;
}

function GetValue()
{
    var myarray= new Array("item1","item2","item3");
    var random = myarray[Math.floor(Math.random() * myarray.length)];
   document.getElementById("message").innerHTML=random;
}
<input type="button" id="btnSearch" value="Search" onclick="GetValue();" />
<p id="message" ></>



Aucun commentaire:

Enregistrer un commentaire