Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a function named greet.
PHP
<?php function [1]() { echo "Hello!"; } ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different function name than called.
✗ Incorrect
The function name must be greet to match the definition.
2fill in blank
mediumComplete the code to call the function greet.
PHP
<?php
greet[1];
?> Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting parentheses when calling a function.
✗ Incorrect
Functions in PHP are called with parentheses ().
3fill in blank
hardFix the error in the function definition by completing the code.
PHP
<?php function greet[1] { echo "Hello!"; } ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting parentheses in function definitions.
✗ Incorrect
Function definitions require parentheses () even if no parameters are used.
4fill in blank
hardFill both blanks to create a function that takes a name and prints a greeting.
PHP
<?php function greet([1]) { echo "Hello, " . [2] . "!"; } ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the dollar sign in parameter names.
✗ Incorrect
In PHP, function parameters must have a $ before the variable name, and the same variable is used inside the function.
5fill in blank
hardFill all four blanks to create a function that returns the sum of two numbers.
PHP
<?php function add([1], [2]) { return [3] + [4]; } ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent variable names or missing dollar signs.
✗ Incorrect
The function parameters and return statement must use the same variable names with dollar signs.