Challenge - 5 Problems
Console Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of console.count usage
What will be printed to the console after running this Node.js code snippet?
Node.js
console.count('label'); console.count('label'); console.count('other'); console.count('label');
Attempts:
2 left
💡 Hint
console.count keeps track of how many times a label has been counted.
✗ Incorrect
The console.count method prints the label followed by the number of times it has been called with that label. Each call increments the count for that label.
❓ Predict Output
intermediate2:00remaining
Behavior of console.assert with false condition
What will be the output when running this Node.js code?
Node.js
console.assert(false, 'Assertion failed!'); console.assert(true, 'This will not show');
Attempts:
2 left
💡 Hint
console.assert only prints the message if the first argument is false.
✗ Incorrect
console.assert prints the message only if the condition is false. It does not throw an error, just logs the message.
❓ Predict Output
advanced2:00remaining
Output of console.group and console.groupEnd
What will be the console output of this Node.js code snippet?
Node.js
console.log('Start'); console.group('Group 1'); console.log('Inside group'); console.groupEnd('Group 1'); console.log('End');
Attempts:
2 left
💡 Hint
console.group indents the following logs until console.groupEnd is called.
✗ Incorrect
console.group indents the output of subsequent logs until console.groupEnd is called. The group label itself is printed without indentation.
❓ Predict Output
advanced2:00remaining
Effect of console.time and console.timeEnd
What will this Node.js code print to the console?
Node.js
console.time('timer'); setTimeout(() => { console.timeEnd('timer'); }, 100);
Attempts:
2 left
💡 Hint
console.timeEnd prints the elapsed time since console.time was called with the same label.
✗ Incorrect
console.time starts a timer with a label. console.timeEnd stops the timer and prints the elapsed time. The time will be close to the delay in setTimeout.
❓ lifecycle
expert3:00remaining
Understanding console.trace output
What does the following Node.js code output when executed?
Node.js
function a() {
b();
}
function b() {
c();
}
function c() {
console.trace('Trace here');
}
a();Attempts:
2 left
💡 Hint
console.trace prints the call stack from the point it is called.
✗ Incorrect
console.trace prints the message and the full call stack showing the order of function calls leading to it, starting from the current function back to the entry point.