this is a dice game by using form to display

it have 3 dices in the function

but when i win, it cant extra money.

<html>
<head>
<script>
function init()
{
	bal=2000;
	form1.balance.value=bal;
	form1.balance.disabled=true;
	form1.bynum.disabled=true;
	form1.buy.disabled=true;
	form1.status.disabled=true;
	
}
function restart()
{
	
		
		
			form1.balance.disabled=false;
			form1.bynum.disabled=false;
			form1.buy.disabled=false;
			form1.status.disabled=false;
			
		
}

function roll()
{
	
	var s=Math.floor(Math.random()*15)+3;
	form1.status.value=s;
		
		if(form1.bynum.value==s)
			
				form1.balance.value + form1.buy.value;
			
			
		else		
			
				form1.balance.value -= form1.buy.value;

	
		
			
}

function quit()
{
	alert("Thanks for playing. Good Bye");
		return init();
}
</script>	
</head>
<body onLoad="init()">

	<form name="form1">
	<table border="1">
	<tr>
		<td>Balance:</td><td colspan="4"><input type="text" name="balance"></td>
		<td>Buy:</td>
		<td>Status</td>
	</tr>

	<tr>
		<td>By number</td>
		<td colspan="4"><select name="bynum">
		<script>
			for(i=3; i<19;i++)
				document.write("<option>" + i +"</option>");
		
		</script>
		</select>
		</td>
		<td><input type="text" name="buy"></td>
		<td rowspan="2"><textarea name="status"></textarea></td>
	</tr>
	<tr>
		<td>odd or even:</td> 
		<td>odd:</td><td><p onClick="roll()";><input type="radio" name="choose"></td>
		<td>Even:</td><td><p onClick="roll()";><input type="radio" name="choose"></td>
	</tr>
	<tr>
		<td></td><td><input type="button" value="Restart" OnClick="restart()"></td>
		<td></td><td><input type="button" value="Roll" onClick="roll()"></td>
		<td></td><td><input type="button" value="Quit" OnClick="quit()"></td>
		
	</tr>
	
	</table>
	</form>

</body>
</html>

Recommended Answers

All 5 Replies

I didn't really look through the code too thoroughly, but:

form1.balance.value + form1.buy.value;

did you want += here?

is still the same. it can extra the money

That fix worked for me. I checked it in firefox, the only problem with += would be string concatenation, but it was definitely adding digits for me...

oh?
lets me try

If you want to add numbers, try total = parseInt(form1.balance.value) + parseInt(form1.buy.value);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.