neil9999
08-28-2003, 05:53 AM
Hi,
I'm making a maths game which doesn't seem to be working. If you click on Next and you have 'Add' selected, it ask you to add two random numbers between 1 and 10 and the next button changes to an enter button (which was working fine before). Then if you enter the (correct) answer into the little box the box in which the question was in should say 'Correct'.
Here's the code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta http-equiv="Content-Language" content="en-gb">
<title></title>
</head>
<body bgcolor="#FF0000">
<script language=javascript>
function next(){
e1=(Math.floor(Math.random() * (1 - 10)) + 10);
e2=(Math.floor(Math.random() * (1 - 10)) + 10);
if(document.getElementById('next').value=="Next" && document.getElementById('type').value=="a"){document.getElementById('next').value='Enter'; add()};
if(document.getElementByld('next').value=="Enter" && document.getElementByld('answer').value==e1+e2){document.getElementById('question').value='Correct'} ;
function add(){
if(document.getElementById('level').value=="e"){document.getElementById('question').value=e1+' plus '+e2;}
}
</script>
<table border="0" width="198" height="99" bordercolor="#000000" style="background-color: #FFFF00; border-style: solid">
<tr>
<td height="33" width="47" colspan="2">
<p align="center">
<select size="1" name="type" id=type>
<option value="a" selected>Add</option>
<option value="t">Take away</option>
<option value="m">Multiply</option>
<option value="d">Divide</option>
</select></p>
</td>
<td height="33" width="52" colspan="2">
<p align="center">
<select size="1" name="level" id=level>
<option value="e" selected>Easy</option>
<option value="m">Medium</option>
<option value="h">Hard</option>
</select></p>
</td>
</tr>
<tr>
<td height="33" width="99" colspan="4">
<p align="center">
<input type="text" name="T1" size="27" id=question>
</p>
</td>
</tr>
<tr>
<td height="33" width="23">
<p align="center"><input type="text" name="answer" size="6" id=answer></td>
<td height="33" width="56" colspan="2">
<p align="center"><button onclick=next() id=next>Next</button></td>
<td height="33" width="24">
<p align="center"><button>Reset</button></td>
</tr>
<tr>
<td height="33" width="23">
<p align="center">Score %:</td>
<td height="33" width="56" colspan="2">
<p align="center">Score Marks:</td>
<td height="33" width="24">
<p align="center">Out of:</td>
</tr>
<tr>
<td height="33" width="23">
<p align="center"><input type="text" name="T1" size="3" id=scorepercent></td>
<td height="33" width="56" colspan="2">
<p align="center"><input type="text" name="T1" size="3" id=score></td>
<td height="33" width="24">
<p align="center"><input type="text" name="T1" size="3" id=outof></td>
</tr>
</table>
</body>
</html>
What have i done wrong?
Thanks,
Neil
I'm making a maths game which doesn't seem to be working. If you click on Next and you have 'Add' selected, it ask you to add two random numbers between 1 and 10 and the next button changes to an enter button (which was working fine before). Then if you enter the (correct) answer into the little box the box in which the question was in should say 'Correct'.
Here's the code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta http-equiv="Content-Language" content="en-gb">
<title></title>
</head>
<body bgcolor="#FF0000">
<script language=javascript>
function next(){
e1=(Math.floor(Math.random() * (1 - 10)) + 10);
e2=(Math.floor(Math.random() * (1 - 10)) + 10);
if(document.getElementById('next').value=="Next" && document.getElementById('type').value=="a"){document.getElementById('next').value='Enter'; add()};
if(document.getElementByld('next').value=="Enter" && document.getElementByld('answer').value==e1+e2){document.getElementById('question').value='Correct'} ;
function add(){
if(document.getElementById('level').value=="e"){document.getElementById('question').value=e1+' plus '+e2;}
}
</script>
<table border="0" width="198" height="99" bordercolor="#000000" style="background-color: #FFFF00; border-style: solid">
<tr>
<td height="33" width="47" colspan="2">
<p align="center">
<select size="1" name="type" id=type>
<option value="a" selected>Add</option>
<option value="t">Take away</option>
<option value="m">Multiply</option>
<option value="d">Divide</option>
</select></p>
</td>
<td height="33" width="52" colspan="2">
<p align="center">
<select size="1" name="level" id=level>
<option value="e" selected>Easy</option>
<option value="m">Medium</option>
<option value="h">Hard</option>
</select></p>
</td>
</tr>
<tr>
<td height="33" width="99" colspan="4">
<p align="center">
<input type="text" name="T1" size="27" id=question>
</p>
</td>
</tr>
<tr>
<td height="33" width="23">
<p align="center"><input type="text" name="answer" size="6" id=answer></td>
<td height="33" width="56" colspan="2">
<p align="center"><button onclick=next() id=next>Next</button></td>
<td height="33" width="24">
<p align="center"><button>Reset</button></td>
</tr>
<tr>
<td height="33" width="23">
<p align="center">Score %:</td>
<td height="33" width="56" colspan="2">
<p align="center">Score Marks:</td>
<td height="33" width="24">
<p align="center">Out of:</td>
</tr>
<tr>
<td height="33" width="23">
<p align="center"><input type="text" name="T1" size="3" id=scorepercent></td>
<td height="33" width="56" colspan="2">
<p align="center"><input type="text" name="T1" size="3" id=score></td>
<td height="33" width="24">
<p align="center"><input type="text" name="T1" size="3" id=outof></td>
</tr>
</table>
</body>
</html>
What have i done wrong?
Thanks,
Neil