Challenge - 5 Problems
PHP Comments Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of PHP code with comments
What is the output of this PHP code snippet?
PHP
<?php // This is a single-line comment echo "Hello"; /* This is a multi-line comment */ echo " World!"; ?>
Attempts:
2 left
💡 Hint
Remember that comments are ignored by PHP and do not affect output.
✗ Incorrect
Single-line and multi-line comments are ignored by PHP. The echo statements print 'Hello' and ' World!' consecutively, resulting in 'Hello World!'.
🧠 Conceptual
intermediate1:30remaining
Purpose of comments in PHP
What is the main purpose of comments in PHP code?
Attempts:
2 left
💡 Hint
Think about what comments do when the PHP engine runs the code.
✗ Incorrect
Comments are ignored by PHP when running the code. They help programmers understand the code by adding explanations or notes.
❓ Predict Output
advanced2:00remaining
Output with nested comment-like syntax
What will this PHP code output?
PHP
<?php /* Start comment // This is not a comment echo "Hello"; End comment */ echo "World!"; ?>
Attempts:
2 left
💡 Hint
Remember that everything inside /* */ is ignored, even if it looks like code.
✗ Incorrect
The entire block between /* and */ is a comment, so echo "Hello"; is ignored. Only echo "World!"; runs, printing 'World!'.
📝 Syntax
advanced1:30remaining
Identify syntax error with comments
Which option will cause a syntax error in PHP?
Attempts:
2 left
💡 Hint
Check if all multi-line comments are properly closed.
✗ Incorrect
Option A has an unclosed multi-line comment which causes a syntax error. All other options have valid comments.
🚀 Application
expert2:30remaining
Count lines of code excluding comments
Given this PHP code, how many lines of actual code (not comments or blank lines) does it contain?
PHP
<?php // Initialize $a = 5; /* Multi-line comment here */ $b = 10; # Another comment $c = $a + $b; echo $c; ?>
Attempts:
2 left
💡 Hint
Count only lines with actual PHP code, ignore comments and empty lines.
✗ Incorrect
The code lines are: $a = 5;, $b = 10;, $c = $a + $b;, and echo $c;. Total 4 lines.