JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 29th, 2012, 05:42 PM
djester55 djester55 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 3 djester55 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 37 m 43 sec
Reputation Power: 0
Yahtzee game in Javascript

i'am having issues with getting the images for my dice to show for my yahtzee game. any idea what i did wrong
Here is what i have
Code:
<html>

<head></head>

<body>

<script language= "JavaScript">
<!--------

function roll(){
var i;
var j;
for (j=1; j<6;j++){
i = Math.floor(random()*6) + 1;  //1-6
document.getElementById("d" +j).innerHTML = "<img src ='dice"+ i +".gif'>";
}

}




//----->
</script>

<table border =1>
<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>
<tr> <td> 1s </td> <td> <input id="box1" type="text"> </td>
<td><input typee"button" value="Roll" onClick="roll()"> < </td>
</tr><tr> <td> 2s </td> <td> <input id="box2" type="text"> </td><td></td>
<tr><td> 3s </td> <td> <input id="box3" type="text"> </td>
<td><input> type ="button" value="New game"> </td></tr>
</table>




<body>
<html>

Reply With Quote
  #2  
Old November 29th, 2012, 06:32 PM
web_loone08's Avatar
web_loone08 web_loone08 is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2008
Posts: 606 web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 16 h 59 m 15 sec
Reputation Power: 69
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'/>";
}
}

</script>

<table border=1>
<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>
<tr> <td> 1s </td> <td> <input id="box1" type="text"/> </td>
<td><input type="button" value="Roll" onClick="roll()"/></td>
</tr><tr> <td> 2s </td> <td> <input id="box2" type="text"/> </td><td></td>
<tr><td> 3s </td> <td> <input id="box3" type="text"/> </td>
<td><input type="button" value="New game"/> </td></tr>
</table>




<body>
<html>

Reply With Quote
  #3  
Old December 1st, 2012, 11:35 PM
djester55 djester55 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 3 djester55 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 37 m 43 sec
Reputation Power: 0
I'am trying to get the dice to show as number such as 1,2,3,4,5,6 and save them into a array so that i can evalated the array of dice later. what am i doing wrong.

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>

Reply With Quote
  #4  
Old December 1st, 2012, 11:42 PM
web_loone08's Avatar
web_loone08 web_loone08 is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2008
Posts: 606 web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 16 h 59 m 15 sec
Reputation Power: 69
Do you want the complete image tag to be placed in an array or just the number results, from each roll? Anyway... try this and see if this is what your wanting:

Code:
var faces = new Array();

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'/>";
face.push("dice" + i);
}
}

Last edited by web_loone08 : December 1st, 2012 at 11:56 PM.

Reply With Quote
  #5  
Old December 2nd, 2012, 01:35 AM
djester55 djester55 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 3 djester55 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 37 m 43 sec
Reputation Power: 0
This is what i'am trying to do
imageshack.us/photo/my-images/202/capturendp.png/

Reply With Quote
  #6  
Old December 3rd, 2012, 07:09 PM
web_loone08's Avatar
web_loone08 web_loone08 is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2008
Posts: 606 web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 16 h 59 m 15 sec
Reputation Power: 69
What you will have to do; is create a function that will look through your array... probably 6 array keys, at a time and compare each of these keys against some validation (that would need to be set-up to compare/contrast your card suites). Then update the value of those input boxes; based on the aforementioned validation.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Yahtzee game in Javascript

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap