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 01-14-2013, 06:18 PM   PM User | #1
triko
New Coder

 
Join Date: Oct 2012
Location: Italy
Posts: 72
Thanks: 3
Thanked 0 Times in 0 Posts
triko is an unknown quantity at this point
Program doesn't work, it's urgent! :D

Hi guy, i'm writing by 13 o'clock, and now don t works can you help!!!
My problem is with, Column and Dozen, that return an NaN...
I must to deliver at 22:30, please solve my problem
Code:
<!DOCTYPE HTML>
<html>
<head>
    <link rel = "stylesheet" type = "text/css" href = "style.css">
    <meta charset = "WINDOWS-1252">
    <title> Roulette </title>
    <style type = "text/css">
    #reset
  {
  position : relative;
  left : 9%;
  }
  #gira
  {
  position : relative;
  left : 5%;
  }
  table
  {
  position : relative;
  left: 5%;
   width: 1250px;
   height: 40px;
  }
  td
  {
   width: 70px;
   height: 70px;
   font-size: 30px;
   text-align: center;
  }
  .rosso
  {
   width: 70px;
   height: 70px;
   background: #FF0000;
  }
  .nero
  {
   width: 70px;
   height: 70px;
   background: #000000;
   color: #FFFFFF;
  }
  .c
  {
   width: 210px;
   height: 70px; 
  }
  body
  {
   background: green;
  }
  .a
  {
   width: 105px;
   height: 70px; 
  }
  .d
  {
   height: 210px; 
  }
  .n
  {
   background: #000000;
   color: #FFFFFF;
  }
  .r
  {
   background: #FF0000;
   
  }
  .gira
  {
    width: 70px;
   height: 70px;
  }
    </style>
    <script type = "text/javascript">
    var result = 0;
    function firstLine (ret)
    {
        var foo = false;
        if (ret == "3" || ret == "6" || ret == "9" || ret == "12" || ret == "15" || ret == "18" || ret == "21" || ret == "24" || ret == "27" || ret == "30" || ret == "33")
        {
            foo = true;
        }
        return foo; 
    }
    function secondLIne (ret)
    {
        var foo = false;
        if (ret == "2" || ret == "5" || ret == "8" || ret == "11" || ret == "14" || ret == "17" || ret == "20" || ret == "23" || ret == "26" || ret == "29" || ret == "32" || ret == "35")
        {
            foo = true;
        }
        return foo; 
    }
    function thirdLine (ret)
    {
        var foo = false;
        if (ret == "1" || ret == "4" || ret == "7" || ret == "10" || ret == "13" || ret == "16" || ret == "19" || ret == "22" || ret == "25" || ret == "28" || ret == "31" || ret == "34")
        {
            foo = true;
        }
        return foo; 
    }
    function firstDozen (ret)
    {
        var foo = false;
        if (ret == "1" || ret == "2" || ret == "3" || ret == "4" || ret == "5" || ret == "6" || ret == "7" || ret == "8" || ret == "9" || ret == "10" || ret == "11" || ret == "12")
        {
            foo = true;
        }
        return foo;  
    }
    function secondDozen (ret)
    {
        var foo = false;
        if (ret == "13" || ret == "14" || ret == "15" || ret == "16" || ret == "17" || ret == "18" || ret == "19" || ret == "20" || ret == "21" || ret == "22" || ret == "23" || ret == "24")
        {
            foo = true;
        }
        return foo;
    }
    function thirdDozen (ret)
    {
        var foo = false;
        if (ret == "25" || ret == "26" || ret == "27" || ret == "28" || ret == "29" || ret == "30" || ret == "31" || ret == "32" || ret == "33" || ret == "34" || ret == "35" || ret == "36")
        {
            foo = true;
        }
        return foo;
    }
    function numberManque (ret)
    {
        var foo = false;
        if (ret == "1" || ret == "2" || ret == "3" || ret == "4" || ret == "5" || ret == "6" || ret == "7" || ret == "8" || ret == "9" || ret == "10" || ret == "11" || ret == "12" || ret == "13" || ret == "14" || ret == "15" || ret == "16" || ret == "17" || ret == "18")
        {
            foo = true;
        }
        return foo;
    }
    function numberPasse (ret)
    {
        var foo = false;
        if (ret == "19" || ret == "20" || ret == "21" || ret == "22" || ret == "23" || ret == "24" || ret == "25" || ret == "26" || ret == "27" || ret == "28" || ret == "29" || ret == "30" || ret == "31" || ret == "32" || ret == "33" || ret == "34" || ret == "35" || ret == "36")
        {
            foo = true;
        }
        return foo;
    }
    function numberRed (ret)
    {
	var foo = false;
	if (ret == "1" || ret == "3" || ret == "5" || ret == "7" || ret == "9" || ret == "12" || ret == "14" || ret == "16" || ret == "18" || ret == "19" || ret == "21" || ret == "23" || ret == "25" || ret == "27" || ret == "30" ||ret == "32" || ret == "34" ||ret == "36")
	{
	    foo = true;
	}
	return foo;
    }
    function numberBlack (ret)
    {
        var foo = false;
        if (ret == "2" || ret == "4" || ret == "6" || ret == "8" || ret == "10" || ret == "11" || ret == "13" || ret == "15" || ret == "17" || ret == "20" || ret == "22" || ret == "24" || ret == "26" || ret == "28" || ret == "29" ||ret == "31" || ret == "33" ||ret == "35")
        {
            foo = true;
        }
        return foo;
    }
    function red (number, money)
    {
	var red = document.getElementById("red").value;
        if (red == "")
            red = 0;
        else
        red = parseInt(red);
	if (numberRed (number))
            money = document.tappeto.money.value=parseInt(document.tappeto.money.value) + red;
        else
            money = document.tappeto.money.value=parseInt(document.tappeto.money.value) - red;
            return money;
    }
    function black (number, money)
    {
	var black = document.getElementById("black").value;
        if (black == "")
            black = 0;
        else
            black = parseInt(black);
        if (numberBlack (number))
            money = document.tappeto.money.value=parseInt(document.tappeto.money.value) + black;
        else
            money = document.tappeto.money.value=parseInt(document.tappeto.money.value) - black;
            return money;
    }
    function odd (number, money)
    {
        var odd = document.getElementById("odd").value;
        if (odd == "")
            odd = 0;
        else
            odd = parseInt(odd);
        if (number%2 == 1)
            money = document.tappeto.money.value=parseInt(document.tappeto.money.value) + odd;
        else
            money = document.tappeto.money.value=parseInt(document.tappeto.money.value) - odd;
            return;
    }
    function even (number, money)
    {
        var even = document.getElementById("even").value;
        if (even == "")
            even = 0;
        else
            even = parseInt(even);
        if (number%2 == 0)
            money = document.tappeto.money.value=parseInt(document.tappeto.money.value) + even;
        else
            money = document.tappeto.money.value=parseInt(document.tappeto.money.value) - even;
            return;
    }
    function manque (number, money)
    {
        var manque = document.getElementById("manque").value;
        manque = parseInt(manque);
        if (numberManque (number))
            money = document.tappeto.money.value=parseInt(document.tappeto.money.value) + manque;
        else
            money = document.tappeto.money.value=parseInt(document.tappeto.money.value) - manque;
            return;
    }
    function passe (number, money)
    {
        var passe = document.getElementById("passe").value;
        passe = parseInt(passe);
        if (numberPasse (number))
            money = document.tappeto.money.value=parseInt(document.tappeto.money.value) + passe;
        else
            money = document.tappeto.money.value=parseInt(document.tappeto.money.value) - passe;
            return;
    }
    function dozen (number, money)
    {
        var dozenOne = document.getElementById("1st12").value;
        var dozenTwo = document.getElementById("2st12").value;
        var dozenThree = document.getElementById("3st12").value;
        if (dozenOne == "")
            dozenOne = 0;
        else
            dozenOne = parseInt(dozenOne);
        if (firstDozen (number))
            money = document.tappeto.money.value = parseInt(document.tappeto.money.value) + (dozenOne * 3);
        else
            money = document.tappeto.money.value = parseInt(document.tappeto.money.value) - dozenOne;
        if (dozenTwo == "")
            dozenTwo = 0;
        else
            dozenTwo = parseInt(dozenTwo);
        if (secondDozen (number))
            money = document.tappeto.money.value = parseInt(document.tappeto.money.value) + (dozenTwo * 3);
        else
            money = document.tappeto.money.value = parseInt(document.tappeto.money.value) - dozenTwo;
        if (dozenThree == "")
            dozenThree = 0;
        else
            dozenThree = parseInt(dozenThree);
        if (thirdDozen (number))
            money = document.tappeto.money.value = parseInt(document.tappeto.money.value) + (dozenThree * 3);
        else
            money = document.tappeto.money.value = parseInt(document.tappeto.money.value) - dozenThree;
        return money;
    }
    function column (number, money)
    {
	var oneColumn = document.getElementById("1stLine").value;
        var twoColumn = document.getElementById("2stLine").value;
        var threeColumn = document.getElementById("3stLine").value;
        if (oneColumn == "")
            oneColumn = 0;
        else
            oneColumn = parseInt(oneColumn);
        if (firstLine (number))
            money = document.tappeto.money.value=parseInt(document.tappeto.money.value) + (oneColumn * 3);
        else
            money = document.tappeto.money.value=parseInt(document.tappeto.money.value) - oneColumn;    
        if (twoColumn == "")
            twoColumn = 0;
        else
            twoColumn = parseInt(twoColumn);
        if (secondLIne (number))
            money = document.tappeto.money.value=parseInt(document.tappeto.money.value) + (twoColumn * 3);
        else
            money = document.tappeto.money.value=parseInt(document.tappeto.money.value) - twoColumn;
        if (threeColumn == "")
            threeColumn = 0;
        else
            threeColumn = parseInt(threeColumn);
        if (thirdLine (number))
            money = document.tappeto.money.value=parseInt(document.tappeto.money.value) + (threeColumn * 3);
        else
            money = document.tappeto.money.value=parseInt(document.tappeto.money.value) - threeColumn;
        return money;
    }
    function number (ball, money)
    {
        var n0 = document.getElementById("0").value;
        var n1 = document.getElementById("1").value;
        var n2 = document.getElementById("2").value;
        var n3 = document.getElementById("3").value;
        var n4 = document.getElementById("4").value;
        var n5 = document.getElementById("5").value;
        var n6 = document.getElementById("6").value;
        var n7 = document.getElementById("7").value;
        var n8 = document.getElementById("8").value;
        var n9 = document.getElementById("9").value;
        var n10 = document.getElementById("10").value;
        var n11 = document.getElementById("11").value;
        var n12 = document.getElementById("12").value;
        var n13 = document.getElementById("13").value;
        var n14 = document.getElementById("14").value;
        var n15 = document.getElementById("15").value;
        var n16 = document.getElementById("16").value;
        var n17 = document.getElementById("17").value;
        var n18 = document.getElementById("18").value;
        var n19 = document.getElementById("19").value;
        var n20 = document.getElementById("20").value;
        var n21 = document.getElementById("21").value;
        var n22 = document.getElementById("22").value;
        var n23 = document.getElementById("23").value;
        var n24 = document.getElementById("24").value;
        var n25 = document.getElementById("25").value;
        var n26 = document.getElementById("26").value;
        var n27 = document.getElementById("27").value;
        var n28 = document.getElementById("28").value;
        var n29 = document.getElementById("29").value;
        var n30 = document.getElementById("30").value;
        var n31 = document.getElementById("31").value;
        var n32 = document.getElementById("32").value;
        var n33 = document.getElementById("33").value;
        var n34 = document.getElementById("34").value;
        var n35 = document.getElementById("35").value;
        var n36 = document.getElementById("36").value;
        var arrayNumber = [n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15, n16, n17, n18, n19, n20, n21, n22, n23, n24, n25, n26, n27, n28, n29, n30, n31, n32, n33, n34, n35, n36];
        for (i = 0; i < arrayNumber.length; i++)
        {
            if (arrayNumber[i] != "")
            {
                if (ball == i)
                    money = document.tappeto.money.value = parseInt(document.tappeto.money.value) + arrayNumber[i] * 36;
                else
                    money = document.tappeto.money.value = parseInt(document.tappeto.money.value) - arrayNumber[i];
            } 
        }
        return money;
    }
    function starts ()
    {
      	soldi.disabled = true;
        
        var i = 0;
        var money = document.getElementById("money").value;
        money = parseInt(money);
        if(document.tappeto.money.value > 0)
        {
            var ball = Math.floor(Math.random()*36); // Pull out random number of 1 to 36
            if (numberRed (ball))
                alert ("The number is:" + " " + ball + " " + "RED");
            else
                alert ("The number is:" + " " + ball + + " " + "BLACK");
            var reds = red (ball, money);
            var blacks = black (ball, money);
            var odds = odd (ball, result);
            var evens = even (ball, money);
            var manques = manque (ball, money);
            var passes = passe (ball, money);
            var dozens = dozen (ball, money);
            var columns = column (ball, money);
            var numbers = number (ball, money);
        }
         else
         {
                alert("You don't have enough money for play again!!!");
                alert("RETRIES!!!")
                window.open("Roulette.html");
                window.opener.close();
        }
        
    }
    function onlynumber(field)
    {
        if (isNaN(field.value))
        {
            alert("NUMBERS ONLY!!!");
            field.value = field.value.substr(0, field.value.length-1);
        }
    }
    function stack()
    {
        var Jackpot = 0;
        Jackpot = parseInt(prompt("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n$                     Welcome to Roulette                           $\n$        How much money you want to join?                 $\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"));
        document.tappeto.money.value = Jackpot;
    }
    </script>
</head>
<body>

</body>
</html>
triko is offline   Reply With Quote
Old 01-14-2013, 06:19 PM   PM User | #2
triko
New Coder

 
Join Date: Oct 2012
Location: Italy
Posts: 72
Thanks: 3
Thanked 0 Times in 0 Posts
triko is an unknown quantity at this point
This is the second part to insert in body
Code:
<form name="tappeto"> 
      <table>
        <tr>
        <td>
      <table id="tabella" border="2">
    	<tr>
    	<td></td>
			<td class="rosso">3 <br />	<input id = "3" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="3" /></td>
			<td class="nero">6 <br />	<input id = "6" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="6" /></td>
			<td class="rosso">9 <br />	<input id = "9" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="9" /></td>
			<td class="rosso">12 <br />	<input id = "12" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="12" /></td>
			<td class="nero">15 <br />	<input id = "15" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="15" /></td>
			<td class="rosso">18 <br />	<input id = "18" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="18" /></td>
			<td class="rosso">21 <br />	<input id = "21" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="21" /></td>
			<td class="nero">24 <br />	<input id = "24" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="24" /></td>
			<td class="rosso">27 <br />	<input id = "27" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="27" /></td>
			<td class="rosso">30 <br />	<input id = "30" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="30" /></td>
			<td class="nero">33 <br />	<input id = "33" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="33" /></td>
			<td class="rosso">36 <br />	<input id = "36" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="36" /></td>
			<td>1st Line <br />		<input id = "1stLine" type= "text" onKeyUp="onlynumber(this)" value="" size=5px name="a2_to_11" /></td>
      </tr>
      <tr>
                        <td>0 <br />			<input id = "0" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="0" /></td>
			<td class="nero">2 <br />	<input id = "2" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="2" /></td>
			<td class="rosso">5 <br />	<input id = "5" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="5" /></td>
			<td class="nero">8 <br />	<input id ="8" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="8" /></td>
			<td class="nero">11 <br />	<input id ="11" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="11" /></td>
			<td class="rosso">14 <br />	<input id ="14" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="14" /></td>
			<td class="nero">17 <br />	<input id ="17" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="17" /></td>
			<td class="nero">20 <br />	<input id ="20" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="20" /></td>
			<td class="rosso">23 <br />	<input id ="23" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="23" /></td>
			<td class="nero">26 <br />	<input id ="26" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="26" /></td>
			<td class="nero">29 <br />	<input id ="29" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="29" /></td>
			<td class="rosso">32 <br />	<input id ="32"type="text" onKeyUp="onlynumber(this)" value="" size=5px name="32" /></td>
			<td class="nero">35 <br />	<input id ="35" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="35" /></td>
			<td>2nd Line <br />		<input id ="2stLine" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="a2_to_12" /></td>
      </tr>
      <tr>
      <td></td>
			<td class="rosso">1 <br />	<input id ="1" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="1" /></td>
			<td class="nero">4 <br />	<input id ="4" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="4" /></td>
			<td class="rosso">7 <br />	<input id ="7" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="7" /></td>
			<td class="nero">10 <br />	<input id ="10" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="10" /></td>
			<td class="nero">13 <br />	<input id ="13" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="13" /></td>
			<td class="rosso">16 <br />	<input id ="16" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="16" /></td>
			<td class="rosso">19 <br />	<input id ="19" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="19" /></td>
			<td class="nero">22 <br />	<input id ="22" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="22" /></td>
			<td class="rosso">25 <br />	<input id ="25" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="25" /></td>
			<td class="nero">28 <br />	<input id ="28" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="28" /></td>
			<td class="nero">31 <br />	<input id ="31" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="31" /></td>
			<td class="rosso">34 <br />	<input id ="34" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="34" /></td>
			<td>3rd Line <br />		<input id ="3stLine" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="a2_to_13" /></td>
      </tr>
      </table>
      <table border="2">
                        <td class="c">1st 12 <br />     <input id = "1st12" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="a1st_12" /></td>
			<td class="c">2nd 12 <br />	<input id = "2st12" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="a2st_12" /></td>
			<td class="c">3rd 12 <br />	<input id = "3st12" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="a3st_12" /></td>
      </table>
      <table border="2">
                        <td class="a">1 - 18 <br />     <input id = "manque" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="a1_18" /></td>
			<td class="a">Even <br />	<input id = "even" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="Even" /></td>
			<td class="r">Red <br />	<input id = "red" type="text" id = "red" onKeyUp="onlynumber(this)" value="" size=5px name="Red" /></td>
			<td class="n">Black <br />	<input id = "black" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="Black" /></td>
			<td class="a">Odd <br />	<input id = "odd" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="Odd" /></td>
			<td class="a">19 - 36 <br />	<input id = "passe" type="text" onKeyUp="onlynumber(this)" value="" size=5px name="a19_36" /></td>
      </table>
      </td>
      <td>
      </td>
      </tr>
      </table>
      <input id="reset" type="reset" value="Reset all"> <br><br>
      <center>
        <input type = "button" value = "INSERT MONEY" id="soldi"  onclick = "stack ()" /><br />
            <font SIZE = 5>Your Money</font>:<br />$<input type = "text" id = "money" style = "text-align:center;" DISABLED/>$<br><br />
        <input type="button" id = "start"  value="START ROULETTE" onclick = "starts ()" /><br><br>
      
      </center>
      </form>
triko is offline   Reply With Quote
Old 01-14-2013, 09:27 PM   PM User | #3
Goos
New Coder

 
Join Date: Apr 2011
Posts: 45
Thanks: 0
Thanked 11 Times in 11 Posts
Goos is an unknown quantity at this point
If you comment out all checks and then add them one by one. You'll find that the problem lies within your manque and passe functions, instead of your dozen and column functions.
You can easily fix them by adding a check for an empty string, like you do in your black, red, even and odd functions.

Another thing I noticed is way of getting a random number.
Math.random gives a number in the range [0, 1). So from 0 up to but including 1.
That means:
0 <= (Math.random() * 36) < 36
0 <= Math.floor(Math.random() * 36) <= 35
So your code will give an integer in from 0 to 35, instead of 1 to 36.

You can use the following function to get a random number within a certain range.
Code:
function random(min, max){
  Math.floor(Math.random() * (max - min + 1)) + min;
};
Goos is offline   Reply With Quote
Old 01-15-2013, 12:22 AM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Since this appears to be for a roulette wheel, that means that it will have spaces numbered from 0 (ZERO!) to 36. [In the USA, it would "00" and "0" and 1 to 36.]

So I think what he really wants is
Code:
var ball = Math.floor(Math.random()*37); // get a number from 0 to 36
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant 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 03:47 PM.


Advertisement
Log in to turn off these ads.