Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' will check for negative numbers.
Using '==' checks for equality, not positivity.
✗ Incorrect
The condition $number > 0 checks if the number is positive.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' will check for odd numbers instead.
Using '>' or '<' does not correctly check for evenness.
✗ Incorrect
The condition $number % 2 == 0 checks if the number is even.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' will print "Positive" for negative numbers.
Using '==' only checks for zero, not positivity.
✗ Incorrect
The condition $number > 0 correctly checks for positive numbers.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' for negative check.
Using '!=' instead of '==' for zero check.
✗ Incorrect
The first condition $number < 0 checks for negative numbers, and the second $number == 0 checks for zero.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' instead of '<' for the first condition.
Using '>' instead of '<=' for the second condition.
✗ Incorrect
The first condition $value < 10 prints "Small". The second $value <= 20 prints "Medium". Otherwise, it prints "Large".