私はこのプロジェクトに取り組んでおり、いくつかの問題に遭遇し続けています。まず、正しいパーセンテージを計算して出力する必要があるクイズです (すべてのコードは最後にあります)。現在の問題は、正しい答えがあり、変数が定義されている場合でも、常に 0% を計算していることです。私の2番目の問題は、粘着性がなく、粘着性がある必要があることです. 何が起こっているのかわかりません。私は今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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
<form method="post">
<?php
$score = 0;
$percent = 0;
//checking submit button
if(isset($_POST['submit'])){
}
//multi-dimensional arrays for questions, selections, and answers
$questions = array(
'q1' => array('question' => 'Which is optional to making Easy Fudge?',
'choice 1' => 'Nuts',
'choice 2' => 'Condensed Milk',
'choice 3' => 'semi-sweet morsels',
'choice 4' => 'bakers chocolate <br />',
'answer' => 'nuts
'),
'q2' => array('question' => 'One square of bakers chocolate is optional to help enhance the flavor and texture?',
'choice 1' => 'Yes',
'choice 2' => 'No',
'choice 3' => 'I do not know what this bakers chocolate is.',
'choice 4' => 'Maybe. <br />',
'answer' => 'Yes', ),
'q3' => array('question' => 'Between prepration time, cooking time, and cooling time, how long does it take to make Easy Fudge?',
'choice 1' => '130 minutes',
'choice 2' => '131 minutes',
'choice 3' => '132 minutes',
'choice 4' => '133 minutes <br />',
'answer' => '131 minutes',),
'q4' => array('question' => 'If divided into 48 pieces, 2 pieces of this fudge is how many calories?',
'choice 1' => '140 calories',
'choice 2' => '150 calories',
'choice 3' => '160 calories',
'choice 4' => '170 calories <br />',
'answer' => '160 calories'),
'q5' => array('question' => 'You combine your morsels and sweetend condensed milk in a medium sauce pan over which heat?',
'choice 1' => 'low',
'choice 2' => 'medium-low',
'choice 3' => 'medium',
'choice 4' => 'high <br />',
'answer' => 'low'),
);
//radio buttons and selectability
foreach($questions as $key => $question){
echo $question['question'] . '<br />';
// TODO: check the POST value and compare to this value (ie. "one")
echo '<input type="radio" name = "'.$key.'" value="one"> ' . $question['choice 1'] . '<br />';
//echo (isset($_POST['radio'] and $_POST['radio']== "one") )? "checked" : "";
echo '<input type="radio" name = "'.$key.'" value="two" >' . $question['choice 2'] . '<br />';
echo '<input type="radio" name = "'.$key.'" value="three"> ' . $question['choice 3'] . '<br />';
echo '<input type="radio" name = "'.$key.'" value="four"> ' . $question['choice 4'] . '<br />';
}
//looping through the questions with nested loops
if (isset($_POST["submit"])) {
foreach($questions as $key => $question){
if ( $question['answer']== $_POST[$key]){
$score++;
}else{ $score = $score;
}
}echo $score;
}//= ($score/5)*100 . "%";
?>
<input name="submit" type="submit" />
</form>
</body>
</html>