PHP练习饼干

时间:2016-06-03 21:21:04

标签: php

当我回答正确的问题时,我需要获得+10分,但这不符合我的代码:

嗨,谢谢你的回答,我现在正在尝试这个但是如果我回答好问题,那么得分不会上升10:

    <?php
    // de functie rand() bepaalt een random getal tussen het eerste en       tweede opgegeven getal
$getal1 = rand (1, 10);
$getal2 = rand (1, 20);
$score = 0;

if(isset($_POST['verzend'])){
    $antwoord = $_POST['uitkomst'];
    $somantwoord = $getal1 * $getal2;

    if($antwoord == $somantwoord)
    {
        $score + 10;
    }
}

echo $score;

HTML

<form method='post' action='index.php'>
 <input name='getal1' type='text' disabled value='$getal1'>&nbsp;*&nbsp;
 <input name='getal2' type='text' disabled value='$getal2'> =
 <input name='uitkomst' type='text' value='' id='uitkomst'>
 <input type='submit' value='verzend' name='verzend'>
 </form>

1 个答案:

答案 0 :(得分:1)

尝试以下代码:

<?php
// de functie rand() bepaalt een random getal tussen het eerste en       tweede opgegeven getal
$getal1 = rand(1, 10);
$getal2 = rand(1, 20);
$score = 0;

if(isset($_POST['verzend'])) {
    $antwoord = (int)$_POST['uitkomst'];
    $somantwoord = $getal1 * $getal2;

    if($antwoord === $somantwoord) {
        $score += 10;
    }
}

echo $score;