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>
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;
};
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.