基本上我试图用0,100之间的2个随机变量显示数学方程式。 我需要存储2个不同的变量:正确的问题数量和回答的总问题。 仅通过一次显示一个问题并在提交时,提示用户是否要继续回答问题,或者如果继续则停止然后刷新随机值。在停止显示3个存储的变量时。 格式为“”正确和“”回答的总问题。
<html>
<head>
<title></title>
<?php
function displayQuestion(){
$firstVal = rand(0,100);
$secondVal = rand(0,100);
$valTotal = $firstVal + $secondVal;
echo $firstVal . "+" . $secondVal . "=";
}
function answersCorrect(){
$answer = 0;
$firstVal = rand(0,100);
$secondVal = rand(0,100);
$valTotal = $firstVal + $secondVal;
do {$valTotal;
$answer ++;
function displayAnswer() {
if ($answer == $valTotal){
$correct ++;
$answer ++;
}
echo "<p>You got {$correct} answers correct out of {$answer}.</p>";
}
}
while ($answer == $valTotal);
$correct = 0;
}
?>
<script>
function query(){
prompt("More questions (y/n)?");
if (prompt != y || Y){
<?php
echo "answersCorrect();";
?>
} else {
function reloadPage(){
location.reload();
}
}
}
</script>
</head>
<body>
<form action="calculate_randMath.php" method="post" id="mathsForm" name="answer">
<p>Question: <?php echo displayQuestion(); ?> </p>
<p>Your answer: <input type="text" name="answer" id="$answer"/></p>
<p><input type="submit" value="answer" name="Submit" onClick="query()" /></p>
</form>
</body>
</html>