Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-03-2012, 04:49 AM   PM User | #1
djester55
New to the CF scene

 
Join Date: Dec 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
djester55 is an unknown quantity at this point
Yahtzee game in Javascript

I'am trying to get the dice to show as number such as 1,2,3,4,5,6 in the top 5 boxes instead of the dice and save them into a array so that i can evalated the array of dice later. what am i doing wrong.
This is what i'am trying to do
imageshack.us/photo/my-images/202/capturendp.png/
Code:
<html>

<head></head>

<body>

<script>


function roll()
{
var i;
var j;

for (j=1; j<6;j++) {
i = Math.floor(Math.random()*6) + 1;  //1-6
document.getElementById("d"+j).innerHTML = "<img src ='dice"+ i +".gif'/>";
<img src="dice1.gif" name="1">
<img src="dice2.gif" name="2">
<img src="dice3.gif" name="3">
<img src="dice4.gif" name="4">
<img src="dice5.gif" name="5">
<img src="dice6.gif" name="6">
var faces = new Array(
 "dice1.gif",
 "dice2.gif",
 "dice3.gif",
 "dice4.gif",
 "dice5.gif",
 "dice6.gif",
);

}
}

 </script>

<b><CENTER>
<FONT SIZE=7> Yahtzee</FONT>
</b></CENTER>


<table border="1" align="center">
<tr>
<td id="d1"> <img src="dice0.gif"/> </td>
<td id="d2"> <img src="dice0.gif"/> </td>
<td id="d3"> <img src="dice0.gif"/> </td>
<td id="d4"> <img src="dice0.gif"/> </td>
<td id="d5"> <img src="dice0.gif"/> </td>
</tr>


<table border="1" align="center">
<tr> <td> 1's </td> <td> <input id="box1" type="text"/> </td>
</tr><tr> <td> 2's </td> <td> <input id="box2" type="text"/> </td><td></td>
<tr><td> 3's </td> <td> <input id="box3" type="text"/> </td>
<tr><td> 4's </td> <td> <input id="box4" type="text"/> </td>
<td><input type="button" value="Roll" onClick="roll()"/></td>
<tr><td> 5's </td> <td> <input id="box5" type="text"/> </td>
<tr><td> 6's </td> <td> <input id="box6" type="text"/> </td>
<tr><td> 3 of a kind </td> <td> <input id="box7" type="text"/> </td>
<tr><td> 4 of a kind </td> <td> <input id="box8" type="text"/> </td>
<tr><td> Full house </td> <td> <input id="box9" type="text"/> </td>
<tr><td> Sm straight </td> <td> <input id="box10" type="text"/> </td>
<tr><td> Lg straight </td> <td> <input id="box11" type="text"/> </td>
<td><input type="button" value="New game"/> </td></tr>
<tr><td> Yahtzee </td> <td> <input id="box12" type="text"/> </td>
<tr><td> Chance </td> <td> <input id="box13" type="text"/> </td>
<tr><td> Total </td> <td> <input id="box14" type="text"/> </td>
</table>




<body>
<html>
djester55 is offline   Reply With Quote
Old 12-03-2012, 12:10 PM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
You cannot mix Javascript and HTML code inside of a <script> tag. So first of all you'll have to remove the HTML <img> tags from the <script> tag.

But there are several more issues which make me believe you should start taking some courses first.

- Two opening <body> tags, no closing </body> tag
- Two opening <html> tags, no closing </html> tag
- You define an array "faces" that you never (need to) use
- <center> and <font> have been deprecated long time ago
devnull69 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:29 AM.


Advertisement
Log in to turn off these ads.