1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| <?php
$tabLettre=array(0=>"dix", 1=>"un", 2=>"deux", 3=>"trois", 4=>"quatre", 5=>"cinq",6=>"six", 7=>"sept", 8=>"huit", 9=>"neuf", 10=>"plus", 11=>"fois");
if(!empty($_POST["valider"]))
{
$a= ($_POST["a"]==0) ? 10 : $_POST["a"];
$b= ($_POST["b"]==0) ? 10 : $_POST["b"];
switch($_POST["c"])
{
case 10 :
$calc=$a + $b;
break;
case 11 :
$calc=$a * $b;
break;
}
echo ($calc==$_POST["result"]) ? 'ok' : 'rate';
}
$a=rand(0,9);//chiffre 1 de 1 a 10 (0=10)
$b=rand(0,9);//chiffre 2 de 1 a 10 (0=10)
$c=rand(10,11);//type de l'operation + et * pour ne pas se retrouver avec des chiffres negatifs ou a virgule.
echo '<br />Combien font : '.$tabLettre[$a].' '.$tabLettre[$c].' '.$tabLettre[$b].' ?';
echo '<FORM method="POST" action="index.php">
<input type="text" name="result" value="" />
<input type="hidden" name="a" value="'.$a.'" />
<input type="hidden" name="b" value="'.$b.'" />
<input type="hidden" name="c" value="'.$c.'" />
<input type="submit" name="valider" value="Valider" />
</FORM>';
?> |
Partager