0
0
PHPprogramming~10 mins

Why conditional flow is needed in PHP - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if a number is positive.

PHP
<?php
$number = 5;
if ($number [1] 0) {
    echo "Positive number";
}
?>
Drag options to blanks, or click blank then click option'
A!=
B<
C==
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' will check for negative numbers.
Using '==' checks for equality, not positivity.
2fill in blank
medium

Complete the code to print 'Even' if the number is even.

PHP
<?php
$number = 4;
if ($number % 2 [1] 0) {
    echo "Even";
}
?>
Drag options to blanks, or click blank then click option'
A>
B!=
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' will check for odd numbers instead.
Using '>' or '<' does not correctly check for evenness.
3fill in blank
hard

Fix the error in the condition to check if a number is negative.

PHP
<?php
$number = -3;
if ($number [1] 0) {
    echo "Negative number";
}
?>
Drag options to blanks, or click blank then click option'
A<
B>
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' checks for positive numbers instead.
Using '==' checks for zero, not negativity.
4fill in blank
hard

Fill both blanks to create a condition that checks if a number is between 1 and 10.

PHP
<?php
$number = 7;
if ($number [1] 1 && $number [2] 10) {
    echo "Number is between 1 and 10";
}
?>
Drag options to blanks, or click blank then click option'
A>
B<
C>=
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using only '>' or '<' excludes the boundary numbers.
Mixing up the operators can cause wrong results.
5fill in blank
hard

Fill all three blanks to create a condition that checks if a number is positive, even, and less than 20.

PHP
<?php
$number = 16;
if ($number [1] 0 && $number % 2 [2] 0 && $number [3] 20) {
    echo "Number is positive, even, and less than 20";
}
?>
Drag options to blanks, or click blank then click option'
A>
B==
C<
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' instead of '>' includes zero, which is not positive.
Using '!=' instead of '==' for evenness checks odd numbers.
Using '>=' instead of '<' for the upper limit includes 20.