mardi 7 mars 2017

PHP number guesser

So I'm trying to make this site which guesses a inputted number from another site and then see if it gets the random number correct, and for this I have some different options telling you how close you got to the correct number, no matter how hard I try though, it seems to fail to give the right answer for

elseif ($_GET["tal"] < $tal - 19 && $_GET["tal"] > $tal + 49)
{
echo '<p style="color:blue">Du er ikke helt ved siden af</p>';
}

though all the other answers seems to be correct, I've changed the get value, and random number to static values to make it easier to see what I try to get. `

    $_GET["tal"] = 30;
    $tal = 40;
    if ($_GET["tal"] == $tal)
    {
    echo '<p style="color:green">Flot - rigtigt gættet!</p>';
    }
    elseif ($_GET["tal"] < 0 || $_GET["tal"] > 100)
    {
    echo '<p style="color:red">Uden for den angivne interval på 1-100</p>';
    }
    elseif ($_GET["tal"] < $tal + 50)
    {
    echo '<p style="color:red">Meget langt forbi</p>';
    }
    elseif ($_GET["tal"] < $tal - 19 && $_GET["tal"] > $tal + 49)
    {
    echo '<p style="color:blue">Du er ikke helt ved siden af</p>';
    }
    else {
    echo '<p style="color:black">Tampen brænder</p>';
    }
`

Any help to resolve this, and possibly an explanation why the other answers wont appear, would be very helpful!

Aucun commentaire:

Enregistrer un commentaire