javasnip

12-03-2012, 06:53 PM

Hi guys, started javascript 2 weeks ago and started working on a basic card came.. Im trying to get to cards with the same number to win. it is real basic now.. and I have it some what working but I want it to show images instead of the numbers here is the code:

<html>

<head><title>Cards</title>

<script type="text/javascript">

function spin()

{

var rands1 = Math.ceil((Math.random()*4));

var randn1 = Math.ceil((Math.random()*13));

var img = new Image();

if (randn1==10)

{

randn1="0"

}

if (randn1==11)

{

randn1="J"

img.src = "weba.jpg";

}

if (randn1==12)

{

randn1="Q"

}

if (randn1==13)

{

randn1="K"

}

cardname1=rands1+"-"+randn1+".jpg";

document.getElementById("sometext").innerHTML = cardname1;

var rands2 = Math.ceil((Math.random()*4));

var randn2 = Math.ceil((Math.random()*13));

if (randn2==10)

{

randn2="0"

}

if (randn2==11)

{

randn2="J"

}

if (randn2==12)

{

randn2="Q"

}

if (randn2==13)

{

randn2="K"

}

cardname2=rands2+"-"+randn2+".jpg";

document.getElementById("sometext2").innerHTML = cardname2;

if (((randn1==0) && (randn2==0) ||(randn1==1) && (randn2==1) ||(randn1==2) && (randn2==2) ||(randn1==3) && (randn2==3) ||(randn1==4) && (randn2==4)))

{

document.getElementById("sometext3").innerHTML = "snap";

}

else

{

document.getElementById("sometext3").innerHTML = "thi is fun";

}

}

</script>

</head>

<body>

<br/><br/><br/><br/>

<button type="button" onclick="spin()">deal</button>

<div id="sometext">A</div>

<div id="sometext2">B</div>

<div id="sometext3">who is going to win</div>

</body>

</html>

<html>

<head><title>Cards</title>

<script type="text/javascript">

function spin()

{

var rands1 = Math.ceil((Math.random()*4));

var randn1 = Math.ceil((Math.random()*13));

var img = new Image();

if (randn1==10)

{

randn1="0"

}

if (randn1==11)

{

randn1="J"

img.src = "weba.jpg";

}

if (randn1==12)

{

randn1="Q"

}

if (randn1==13)

{

randn1="K"

}

cardname1=rands1+"-"+randn1+".jpg";

document.getElementById("sometext").innerHTML = cardname1;

var rands2 = Math.ceil((Math.random()*4));

var randn2 = Math.ceil((Math.random()*13));

if (randn2==10)

{

randn2="0"

}

if (randn2==11)

{

randn2="J"

}

if (randn2==12)

{

randn2="Q"

}

if (randn2==13)

{

randn2="K"

}

cardname2=rands2+"-"+randn2+".jpg";

document.getElementById("sometext2").innerHTML = cardname2;

if (((randn1==0) && (randn2==0) ||(randn1==1) && (randn2==1) ||(randn1==2) && (randn2==2) ||(randn1==3) && (randn2==3) ||(randn1==4) && (randn2==4)))

{

document.getElementById("sometext3").innerHTML = "snap";

}

else

{

document.getElementById("sometext3").innerHTML = "thi is fun";

}

}

</script>

</head>

<body>

<br/><br/><br/><br/>

<button type="button" onclick="spin()">deal</button>

<div id="sometext">A</div>

<div id="sometext2">B</div>

<div id="sometext3">who is going to win</div>

</body>

</html>