samedi 30 septembre 2017

How to make a number appear in a range from 0 to 9?

I am currently completing a project and have come across an error in my coding.

I have a button which calls a JS prompt box asking to enter an integer between 0 and 9.

This number is then used as a game where 3 random integers from 0 and 9 appear every second and when you click on the matching number your score increases.

This is my code so far:

<script>

function chooseNum() 
{
var txt;
var person = prompt("Choose an integer between 0 and 9:");
if (person == null || person == "") {
    txt = "User cancelled the prompt.";
} else {
    txt = person;
}
document.getElementById("chosen").innerHTML = txt;
}

</script>

I want to know exactly how to display random integers in a range from 0 and 9.

Is a code like this on the right track?

<script>

var id = window.setInterval(function(){randomNumber();},1000);

function randomNumber()
{
var rand = Math.floor(Math.random()*9);
$('#number1').html(rand);
}

</script>

Can anyone point me in the right direction?

Cheers.




Aucun commentaire:

Enregistrer un commentaire