Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add two numbers and print the result.
PHP
<?php $a = 5; $b = 3; $result = $a [1] $b; echo $result; ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using minus
- instead of plus +.✗ Incorrect
The plus sign + adds two numbers together.
2fill in blank
mediumComplete the code to multiply two numbers and print the result.
PHP
<?php $x = 7; $y = 4; $product = $x [1] $y; echo $product; ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using plus
+ instead of multiplication *.✗ Incorrect
The asterisk * multiplies two numbers.
3fill in blank
hardFix the error in the code to correctly divide two numbers and print the result.
PHP
<?php $num1 = 10; $num2 = 2; $division = $num1 [1] $num2; echo $division; ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using minus
- or multiplication * instead of division /.✗ Incorrect
The forward slash / divides one number by another.
4fill in blank
hardFill both blanks to create a dictionary of squares for numbers greater than 3.
PHP
<?php $numbers = [1, 2, 3, 4, 5]; $squares = []; foreach ($numbers as $num) { if ($num [1] 3) { $squares[$num] = $num [2] 2; } } print_r($squares); ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than
< instead of greater than >.Using multiplication
* instead of power ** for squaring.✗ Incorrect
The operator > checks if a number is greater than 3. The operator ** raises the number to the power of 2 (square).
5fill in blank
hardFill all three blanks to create an array of numbers and filter those divisible by 2.
PHP
<?php $numbers = range(1, 10); $evens = []; foreach ($numbers as [1]) { if ([2] % 2 [3] 0) { $evens[] = [2]; } } print_r($evens); ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable without
$ sign.Using not equal
!= instead of equal ==.✗ Incorrect
The variable $num is used to loop through numbers. The operator == checks if the remainder is zero, meaning the number is divisible by 2.