Javascript Switch case doesn't work even if conditions are true -


as previous questions coudn't answers solved problem, i've decided post entire code determine issue. problem when button pressed, if 1 of 3 images same (equals others) instance(three 1's appear, or 3 2's appear) no message entered in program outputted instead, nothing happens.

here original question(switch case not working images stored in array)

the html:

<html>      <head>         <meta http-equiv="content-type" content="text/html; charset=utf-8" />         <title>untitled document</title>     </head>      <body>         <form name=slots onsubmit="rollem(); return false;">             <tr>                 <th align=right>usertokens:</th>                 <td align=left>                     <input type=box size=5 name=usertokens readonly value=25>                 </td>             </tr>             <tr>                 <th align=right>your bet:</th>                 <td align=left>                     <input type=box size=5 name=bet>                 </td>             </tr>             <tr>                 <th>                     <input type=submit value="spin slots">                 </th>                 <center>                     <table cellspacing=5 cellpadding=2 border=0>                         <tr>                             <td>                                 <img src=number1test.gif name=slot1>                             </td>                             <td>                                 <img src=number2test.gif name=slot2>                             </td>                             <td>                                 <img src=number3test.gif name=slot3>                             </td>                         </tr>                     </table>                     <input type=text readonly size=33 name=banner>                     </td>             </tr>         </form>     </body>  </html>  </html> 

and js (at end of <body>):

slotitem = new array('number1test', 'number2test', 'number3test'); // create array each slot item image  tokens = 100; // starting tokens  function stopplay() { // call function      if (document.slots.usertokens.value < tokens) // if usertokens less value..     {         alert("you lost tokens")      } else // otherwise, how user gained     {         alert("you gained " + (document.slots.usertokens.value - tokens) + " token pieces.   ");     } }  function rollem() {      if (math.floor(document.slots.usertokens.value) < math.floor(document.slots.bet.value)) {         alert("your bet larger token amount")      }      if (document.slots.bet.value > 1) {         document.slots.banner.value = "bet " + document.slots.bet.value + " usertokens pieces";     } else {         document.slots.banner.value = "bet " + document.slots.bet.value + " usertokens piece";     }      counter = 0;     spinem();  }  function spinem() { // speed of randomly generated pictures      turns1 = 10 + math.floor((math.random() * 5))      (a = 0; < turns1; a++)      {         document.slots.slot1.src = "" + slotitem[a % 3] + ".gif";     }      turns2 = 10 + math.floor((math.random() * 5))      (b = 0; b < turns2; b++)      {         document.slots.slot2.src = "" + slotitem[b % 3] + ".gif";     }      turns3 = 10 + math.floor((math.random() * 5))      (c = 0; c < turns3; c++)      {         document.slots.slot3.src = "" + slotitem[c % 3] + ".gif";     }      counter++;      if (counter < 25) {         settimeout("spinem(counter);", 50);     } else {         checkmatch();     }  }  function checkmatch() {     // problem here, cases seem never happen, program goes else statement, , when 1 case true on webpage, doesnt display anything(nor else statement)     if ((document.slots.slot1.src == document.slots.slot2.src && document.slots.slot2.src == document.slots.slot3.src))         switch (document.slots.slot1) {         case "number1test":             document.slots.banner.value = ("you got 3 in row 1's") // stuff             break;         case "number2test":             document.slots.banner.value = ("you got 3 in row 2's")             break;         case "number3test":             document.slots.banner.value = ("you got 3 in row 3's")             break;     } else {         document.slots.usertokens.value = document.slots.usertokens.value - document.slots.bet.value;         document.slots.banner.value = "no match - lost " + document.slots.bet.value + " token piece(s)";     } } 

add

alert(document.slots.slot1.src); 

before switch() , you'll see real value you're checking. you're missing extension (.gif) , first part of url of image (http://.../).

i think should remember slots' values (in variables) when change images, instead of reading them images' src attributes.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -