mardi 14 avril 2015

Javascript background changing based on function

I have to simulate a function that chooses random numbers between 0 and 37 when I click a button. If it's even, the background is red. If it's odd, the background is black. The initial background is light blue. This is what I have so far, and it is not working.



<html>
<head>
<title>Wheel</title>
<script type="text/javascript">
var currentNum = wheelspins();
document.body.style.backgroundColor = "#00ffff";

function wheelspins()
{
return Math.floor(Math.random() * 37);

if(currentNum % 2 == 0){
style.backgroundColor="#FF0000";
}
else if(currentNum %2 == 1){
style.backgroundColor="#000000";
}
}
</script>
</head>
<body>
<form>

<input type="text" name="Number" value="" id="wheelspins()" size="10"/>
<input type="button" value="Spin Wheel" onclick="document.getElementById('wheelspins()').value=wheelspins();"/>
</form>
</body>
</html>




Aucun commentaire:

Enregistrer un commentaire