memo333
10-10-2012, 07:38 PM
Im programming a dice and coin randomizer, but I cant make the coin works
this is html with js all in one, when I press the TIRA MONEDA button it says undefined...I know its a varible but im clueless plz help :);)
<!DOCTYPE html>
<html>
<head>
<script>
/*
gaga
*/
//random coin
//preload the six images first
var face0=new Image()
face0.src="d1.gif"
var face1=new Image()
face1.src="d2.gif"
var face2=new Image()
face2.src="d3.gif"
var face3=new Image()
face3.src="d4.gif"
var face4=new Image()
face4.src="d5.gif"
var face5=new Image()
face5.src="d6.gif"
</script>
<img src="d1.gif" name="mydice">
<form>
<input type="button" value="Throw dice!" onClick="throwdice()">
<p>
<input type="button" value="TIRA MONEDA!" onClick="sayHello()">
<div id="result"></div>
<script>
function sayHello(){
document.getElementById("result").innerHTML = throwcoin();
}
/*function sayHello(name){
document.getElementById("result").innerHTML = 'Hello ' + name + '!';
}*/
function throwdice(){
//create a random integer between 0 and 5
var randomdice=Math.round(Math.random()*5)
document.images["mydice"].src=eval("face"+randomdice+".src")
}
function throwcoin(){
//create a random integer between 0 and 1
//this.randomcoin=Math.round(Math.random()*1)
this.randomcoin=1;
if(randomcoin===0){return document.getElementById("result").innerHTML = throwcoin.randomcoin;
}
else{return document.write('AGUILA!')}
}
</script>
<title>MEMO MATH TEST</title>
</head>
<body>
<div id="border2">
</div>
</body>
</html>
this is html with js all in one, when I press the TIRA MONEDA button it says undefined...I know its a varible but im clueless plz help :);)
<!DOCTYPE html>
<html>
<head>
<script>
/*
gaga
*/
//random coin
//preload the six images first
var face0=new Image()
face0.src="d1.gif"
var face1=new Image()
face1.src="d2.gif"
var face2=new Image()
face2.src="d3.gif"
var face3=new Image()
face3.src="d4.gif"
var face4=new Image()
face4.src="d5.gif"
var face5=new Image()
face5.src="d6.gif"
</script>
<img src="d1.gif" name="mydice">
<form>
<input type="button" value="Throw dice!" onClick="throwdice()">
<p>
<input type="button" value="TIRA MONEDA!" onClick="sayHello()">
<div id="result"></div>
<script>
function sayHello(){
document.getElementById("result").innerHTML = throwcoin();
}
/*function sayHello(name){
document.getElementById("result").innerHTML = 'Hello ' + name + '!';
}*/
function throwdice(){
//create a random integer between 0 and 5
var randomdice=Math.round(Math.random()*5)
document.images["mydice"].src=eval("face"+randomdice+".src")
}
function throwcoin(){
//create a random integer between 0 and 1
//this.randomcoin=Math.round(Math.random()*1)
this.randomcoin=1;
if(randomcoin===0){return document.getElementById("result").innerHTML = throwcoin.randomcoin;
}
else{return document.write('AGUILA!')}
}
</script>
<title>MEMO MATH TEST</title>
</head>
<body>
<div id="border2">
</div>
</body>
</html>