Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
Why $Answer will never equal to $Facit

The code just displays a simple math question and it then checks if the typed answer is correct or not. And it works flawlessly except that I can't ever make $Answer == $Facit, whatever else I put instead of $Facit works. Ex: 9, ie if ($Answer == 9) {...

it also doesn't seem to have anything to do with local/global scope, because I can echo $Facit inside the if statements.

<div id="MainContainer">
<div class="Qt">
    <?php
        $num1 = rand(1,50);
        $num2 = rand(1,50);
        echo $num1;
        echo "+";
        echo $num2;
        $Facit = $num1 + $num2;
    ?>

</div>


<form>
    
<input type="text" name="Answer">
<button type="submit" name="CalcAns" value="submit"> Submit Answer</button>
</form>
<?php
if (isset($_GET["CalcAns"]) != null )
{
    $Answer = $_GET["Answer"];
    
    if( $Answer == (string)$Facit)
    {
        echo "Correct!";
    }
    else if ($Answer == null)
    {
        echo "Type in an answer";
    }
    else
    {
        echo "Wrong";
    }
}
?> 
</div>
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!