Aoami
I am a FH squatter
- Joined
- Dec 22, 2003
- Messages
- 11,223
Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Learning to Multiply Website</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type = "text/css">
body { background-color: #ddd }
</style>
<script language = "JavaScript" type="text/javascript">
var x,y;
function aNumber() {
return Math.round(Math.random()*(11)+1);
}
function genQuestion() {
dispQ = document.getElementById("questionVal");
x = aNumber();
y = aNumber();
dispQ.value = "What is " + x + " times " + y + " ?";
}
function randomCorrectRes(){
respNumber = Math.round(Math.random()*(1)+1);
switch(respNumber)
{
case 1:
return "Correct";
case 2:
return "Good Answer!";
}
}
function randomIncorrectRes(){
respNumber = Math.round(Math.random()*(1)+1);
switch(respNumber)
{
case 1:
return "No. Please try again.";
case 2:
return "Wrong. Try once more.";
}
}
function buttonPressed() {
answer = document.getElementById("answerVal");
if(answer.value ==""){
window.alert("Null Value!");
}else if(answer.value == (x*y)){
window.alert(randomCorrectRes());
genQuestion();
}else{
window.alert(randomIncorrectRes());
}
answer.value="";
}
</script>
</head>
<body>
<h1>Learning to Multiply Website</h1>
<form name="MyForm" id="MyForm" action="">
<table border = "1">
<tr>
<td><b>What is</b></td>
<td><input id="questionVal" name="question" type="text" /></td>
</tr>
<tr>
<td><b>The answer is</b></td>
<td><input id="answerVal" name="answer" type="text" /></td>
</tr>
<tr>
<td><input value="" name="checkanswer" type="button"
onclick="buttonPressed()" /></td>
</tr>
</table>
</body>
</html>
Basically, i need to fill in the blanks in the table so 'What is' generates the question using the genQuestion function.
'The answer is' You enter manually.
The button should check the answer using the buttonPressed function, and give you a correct or incorrect popup using the randomIncorrectRes and randomCorrectRes functions.
I'm stuck.
Help pwease