0
0
PHPprogramming~10 mins

If statement 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 check if a number is zero or not.

PHP
<?php
$number = 0;
if ($number [1] 0) {
    echo "Number is zero";
} else {
    echo "Number is not zero";
}
?>
Drag options to blanks, or click blank then click option'
A==
B!=
C<
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' will check if the number is not zero.
Using '>' or '<' checks for greater or less than zero, not equality.
3fill in blank
hard

Fix the error in the if statement 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, not negative.
Using '==' checks for equality, not negativity.
4fill in blank
hard

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

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 '>' or '<' alone excludes boundary numbers.
Mixing up '<' and '<=' changes the range.
5fill in blank
hard

Fill all three blanks to create an if-else statement that prints if a number is positive, zero, or negative.

PHP
<?php
$number = [1];
if ($number [2] 0) {
    echo "Positive number";
} elseif ($number [3] 0) {
    echo "Zero";
} else {
    echo "Negative number";
}
?>
Drag options to blanks, or click blank then click option'
A5
B>
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for positive check.
Using '!=' instead of '==' for zero check.