Challenge - 5 Problems
Debug.Log Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Debug.Log statement?
Consider the following Unity C# code snippet. What will be printed in the Console when this runs?
Unity
int score = 10; Debug.Log($"Player score is: {score}");
Attempts:
2 left
💡 Hint
Look at how the $ symbol works with strings in C#.
✗ Incorrect
The $ before the string allows embedding variables inside curly braces. So {score} is replaced by the value 10.
❓ Predict Output
intermediate2:00remaining
What does this Debug.Log print?
Look at this code snippet. What will appear in the Unity Console?
Unity
int x = 5; int y = 3; Debug.Log("Sum is: " + (x + y));
Attempts:
2 left
💡 Hint
Remember how + works with strings and numbers.
✗ Incorrect
The parentheses force the addition before concatenation, so 5 + 3 = 8, then concatenated to the string.
❓ Predict Output
advanced2:00remaining
What error does this Debug.Log cause?
Examine this code snippet. What error will Unity show in the Console?
Unity
int[] numbers = {1, 2, 3}; Debug.Log(numbers[3]);
Attempts:
2 left
💡 Hint
Check the array indices and their valid range.
✗ Incorrect
The array has indices 0,1,2. Accessing index 3 is out of range and causes IndexOutOfRangeException.
❓ Predict Output
advanced2:00remaining
What will this Debug.Log print?
What is the output of this code in the Unity Console?
Unity
string playerName = null; Debug.Log($"Player: {playerName?.ToUpper() ?? "Unknown"}");
Attempts:
2 left
💡 Hint
Look at the null conditional operator and null-coalescing operator.
✗ Incorrect
playerName is null, so playerName?.ToUpper() returns null, then ?? "Unknown" replaces null with "Unknown".
❓ Predict Output
expert2:00remaining
What is the output of this Debug.Log with a loop?
Consider this code. What will be printed in the Unity Console?
Unity
for (int i = 0; i < 3; i++) { Debug.Log($"Count: {i}"); }
Attempts:
2 left
💡 Hint
Remember how for loops count from start to less than end.
✗ Incorrect
The loop runs with i = 0,1,2 and prints each value. It stops before i reaches 3.