lundi 23 novembre 2015

Trouble creating "if then" Javascript statement to change background color of page

I'm working on a project right now that requires we use Javascripts built in RNG to generate a number from 0-37, and then change the background color from blue to black if the number is odd, and blue to red if the number is even. I'm almost certain I've got the commands right, but I still can't figure out what I'm doing wrong. Just looking for a second set of eyes to glance it over that might spot what I'm doing incorrectly.

here's the code that I'm using so far: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

<!DOCTYPE html>
<html>

<script type="text/javascript">

function changeColor () {
    if ( ('wheel' % 2) == 0) {
    document.body.style.backgroundColor = "red";
    }
    else {
    document.body.style.backgroundColor = "black";
}

</script>

<body bgcolor="blue">



<p><font size="4" color="white"><b>First place a bet on a number or color. 
<br>Then, spin the wheel to see if you win.</b></font></p>

<button onclick="myFunction()">Spin the Wheel</button>

<font face="Jokerman" color="white" size="6"><p id="wheel"></p></font>

<script>
function myFunction() {
    var x = Math.floor((Math.random() * 38) + 0);
    document.getElementById("wheel").innerHTML = x;
}
</script>

</body>
</html>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The page loads correctly, the button to generate a number is working properly, but no matter what the result is, the background color remains blue.




Aucun commentaire:

Enregistrer un commentaire