C. Missing parentheses after function name in definition
D. Function call syntax is wrong
Solution
Step 1: Check function definition syntax
Function definitions must have parentheses even if no parameters are used.
Step 2: Verify other parts
The function call sayHello() is correct. The package declaration and import are present, so the only syntax error is the missing parentheses after the function name in the definition.
Final Answer:
Missing parentheses after function name in definition -> Option C
Quick Check:
Function definition needs () [OK]
Hint: Function definitions always need () after name [OK]
Common Mistakes:
Ignoring missing parentheses in function definition
Thinking function call syntax is wrong
Believing the code has no errors
5. You want to print a greeting message multiple times without repeating code. Which approach best uses functions in Go?
hard
A. Write the print statement many times in main
B. Create a function that prints the message and call it repeatedly
C. Use a variable to store the message but print once
D. Write the print statement inside a loop without a function
Solution
Step 1: Understand the goal
We want to avoid repeating the same print code multiple times.
Step 2: Evaluate options for reusability
Only creating a function and calling it repeatedly avoids code repetition and organizes code well.
Final Answer:
Create a function that prints the message and call it repeatedly -> Option B
Quick Check:
Functions avoid repeating code [OK]
Hint: Use functions to avoid repeating code [OK]
Common Mistakes:
Repeating print statements instead of using functions
Using variables without reusing code
Ignoring functions and relying only on loops
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.