0
0
Unityframework~20 mins

Debug.Log for debugging in Unity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Debug.Log Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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}");
AError: score is not defined
BPlayer score is: {score}
CPlayer score is: 0
DPlayer score is: 10
Attempts:
2 left
💡 Hint
Look at how the $ symbol works with strings in C#.
Predict Output
intermediate
2: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));
ASum is: (x + y)
BSum is: 8
CSum is: 53
DSum is: x + y
Attempts:
2 left
💡 Hint
Remember how + works with strings and numbers.
Predict Output
advanced
2: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]);
AIndexOutOfRangeException
BNullReferenceException
CNo error, prints 3
DSyntaxError
Attempts:
2 left
💡 Hint
Check the array indices and their valid range.
Predict Output
advanced
2: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"}");
APlayer: Unknown
BPlayer: null
CNullReferenceException
DPlayer:
Attempts:
2 left
💡 Hint
Look at the null conditional operator and null-coalescing operator.
Predict Output
expert
2: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}");
}
A
Count: 0
Count: 1
Count: 2
Count: 3
B
Count: 1
Count: 2
Count: 3
C
Count: 0
Count: 1
Count: 2
DCount: 3
Attempts:
2 left
💡 Hint
Remember how for loops count from start to less than end.