KseniaTARgv24 PHP tood

Matemaatilised tehted

PHP matemaatilised tehted

Guess 2 numbers...

Game continues...
  • We multiplyed num 1 by num 2. Now number 1 is 50
  • After that we added num 2 the new num 1. Now num 2 is 55
  • What are the original 2 numbers?


    <?php
    // eemalda urlist muutujad
    //https://pastebin.com/Qdb6QDtJ
    function clearVarsExcept($url, $varname) {
        // basename - makes the link relative, url must contain a filename that it returns basename('http://www.ee/index.php') > index.php
        $url = basename($url);
        if (str_starts_with($url, "?")) {
            return "?$varname=".$_REQUEST[$varname];
        }
        // strtok - returns first token after spliting on separator "?" strtoken('index.php?haha=lala', '?') > index.php
        return strtok($url, "?")."?$varname=".$_REQUEST[$varname];
    }
        echo "<h2>Matemaatilised tehted</h2>";
        echo "<a href='https://www.metshein.com/unit/php-matemaatilised-tehted-ulesanne-2/'>
        PHP matemaatilised tehted</a>";
    
        //moistatus
    echo "<h2>Guess 2 numbers...";
    $arv1=10;
    $arv2=5;
    echo "<ul>";
    echo "<li>When you substract 2nd number out of 1st you get  " . ($arv1 - $arv2) ."</li>";
    echo "<li>When you devide number 1 by number 2, you get  " . ($arv1 / $arv2) ."</li>";
    echo "<li>And the devision remainder is  " . ($arv1 % $arv2) ."</li>";
    echo "<li>When you add number 1 number 2, you get  " . ($arv1 + $arv2) ."</li>";
    echo "<li>number 1 times number 2 is  " . ($arv1 * $arv2) ."</li>";
    echo "</ul>";
    
    echo "<h2>Game continues...";
    $arv1 *= $arv2;
    echo "<li>We multiplyed num 1 by num 2. Now number 1 is  " . $arv1 ."</li>";
    $arv2 += $arv1;
    echo "<li>After that we added num 2 the new num 1. Now num 2 is  " . $arv2 ."</li>";
    echo "<h2>What are the original 2 numbers?";
    $arv1=10;
    $arv2=5;
    ?>
    <form name="arvud" action="<?=clearVarsExcept(basename ($_SERVER['REQUEST_URI']), "leht")?>" method="post">
        <br>
        <label for="num1">Arv1</label>
        <input type='number' id='num1' name="arv1" max="10">
        <br>
        <label for="num2">Arv2</label>
        <input type='number' id='num2' name="arv2" max="10">
        <input type="submit" name="submit" value="Kontrolli">
    </form>
    
    <?php
    if (isset($_POST["submit"])){
        if($_REQUEST["arv1"] == $arv1 and  $_REQUEST["arv2"] == $arv2){
        echo "oige";
        echo "<body style = 'color:green'>";
        }
        else{
            echo "noooo";
            echo "<body style = 'color:red'>";
        }
    }
    
    highlight_file('MatTehted.php');
    ?>