vendredi 6 octobre 2017

Random numbers, random colour loops

I'm currently teaching myself HTML/Javascript, with a few challenges set by a colleague.

I'm trying to create loops which will display 3 random numbers between 1-99. Each displaying a random colour. Have done some searching and unable to find anything that incorporates these four aspects of my loop.

Below is where I've got to so far. Any ideas how to convert this into loops?

Many thanks Chris

    <!DOCTYPE html>
<html>
<body>
<center>
<h1>Hello World!</h1>

<h2>10 Random Coloured Numbers</h2>

<p id="no1"></p>
<p id="no2"></p>
<p id="no3"></p>


<script>
document.getElementById("no1","no2","no3").innerHTML =
Math.floor(Math.random() * 101)
document.getElementById("no1","no2","no3").style.color =
'#' + (Math.random() * 0xFFFFFF << 0).toString(16);
</script>




Aucun commentaire:

Enregistrer un commentaire