#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    3
    Rep 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>
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,183
    Rep Power
    184
    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>
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    3
    Rep 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>
  6. #4
  7. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,183
    Rep Power
    184
    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 2nd, 2012 at 12:56 AM.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0
    This is what i'am trying to do
    imageshack.us/photo/my-images/202/capturendp.png/
  10. #6
  11. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,183
    Rep Power
    184
    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.

IMN logo majestic logo threadwatch logo seochat tools logo