Tips och förslag för förbättringar kan diskuteras i denna tråd.
Kod: Markera allt
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS, could be usefull.... -->
<link rel="stylesheet" href="lib/bootstrap.min.css">
<!-- My CSS... but this file is empty.. we lay our trust at bootstrap -->
<link rel="stylesheet" href="styles/main.css">
<script src="lib/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<script src="lib/bootstrap.min.js"></script>
<title>Öva på Multiplikationstabellen?</title>
</head>
<body>
<div class="container-fluid">
<div class="jumbotron">
<form action="<?php echo $_SERVER['php_self']; ?>" method="post">
<?php
// if we got inputzzzzzzz then validate that round.
if (isset ($_POST['submit'])) {
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
$users_answer_is = $_POST['submit'];
$counted_numbers = $_POST['counted_numbers'];
$correct_answers = $_POST['correct_answers'];
$wrong_answers = $_POST['wrong_answers'];
$counted_numbers++;
if (($num1 * $num2) == $users_answer_is) {
$correct_answers++;
} else {
$wrong_answers++;
}
} else {
$counted_numbers = 0;
$correct_answers = 0;
$wrong_answers = 0;
}
// Okay... let's start a new round
do_it_again:
$num1 = rand(1, 10);
$num2 = rand(1, 10);
$answer = $num1 * $num2;
if ($num1 >= 10 && $num2 >= 10) {
goto do_it_again;
}
?>
<div class="form-group">
<div class="row">
<div class="col-1">
<h3 class="font-weight-bolder"><?php echo $num1 . "x" . $num2 . " ="; ?></h3>
</div>
<div class="col-11">
<div class="btn-group btn-group-block">
<?php
$rightAwnser = rand(1, 8);
$value;
for ($i = 1; $i <= 8; $i++) {
if ($i == $rightAwnser) {
$value = $num1 * $num2;
} else {
second_do_it_again:
$value = rand(1, 10) * rand(1, 10);
if ($value >= 100) {
goto second_do_it_again;
}
}
?>
<div class="btn-group">
<input type="submit" name="submit" class="btn btn-success" value="<?php echo $value; ?>">
</div>
<?php
}
?>
</div>
</div>
</div>
</div>
<input type="hidden" name="num1" value="<?php echo $num1; ?>">
<input type="hidden" name="num2" value="<?php echo $num2; ?>">
<input type="hidden" name="counted_numbers" value="<?php echo $counted_numbers; ?>">
<input type="hidden" name="correct_answers" value="<?php echo $correct_answers; ?>">
<input type="hidden" name="wrong_answers" value="<?php echo $wrong_answers; ?>">
<table>
<thead>
<tr>
<th>Räknade tal: <span class="badge badge-info"><?php echo $counted_numbers; ?></span></th>
<th>Antal rätt: <span class="badge badge-success"><?php echo $correct_answers; ?></span></th>
<th>Antal fel: <span class="badge badge-danger"><?php echo $wrong_answers; ?></span></th>
</tr>
</thead>
</table>
</form>
</div>
</div>
</body>
</html>