0
0
PHPprogramming~10 mins

If-else execution flow in PHP - Interactive Code Practice

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 if-else statement to print "Positive" or "Non-positive".

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

Fill both blanks to check if a number is negative or zero.

PHP
<?php
$number = 0;
if ($number [1] 0) {
    echo "Negative number";
} elseif ($number [2] 0) {
    echo "Zero";
} else {
    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 '<' for negative check.
Using '!=' instead of '==' for zero check.
5fill in blank
hard

Fill both blanks to print "Small", "Medium", or "Large" based on the value.

PHP
<?php
$value = 15;
if ($value [1] 10) {
    echo "Small";
} elseif ($value [2] 20) {
    echo "Medium";
} else {
    echo "Large";
}
?>
Drag options to blanks, or click blank then click option'
A<=
B<
C>=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' instead of '<' for the first condition.
Using '>' instead of '<=' for the second condition.