mardi 31 mai 2016

Javascript random generator

I created a random number generator in javascript whose values are in an array. The code is that one

function GetValue()
{
    var names= new Array(1,2,3,4,5);
    var random = names[Math.floor(Math.random() * names.length)];
    //alert(random);
    document.getElementById("message").innerHTML=random;
}
<p>number generator</p>  
<form class="form">
        <div class="form-group">
      <input type="button" id="btnSearch" value="Generatore" onclick="GetValue();"   class="btn btn-default"/>
<p id="message" ></p>
            </div>
        </form>

I'd like to know if it is possible to give a different text in the p tag according to the number generated by the button. Thanks very much and sorry if there is any english error




Aucun commentaire:

Enregistrer un commentaire