Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to exit the Node.js process with a success code.
Node.js
process.[1](0);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using methods like quit or stop which do not exist on process.
Not passing an exit code.
✗ Incorrect
The process.exit() method stops the Node.js process. Passing 0 means success.
2fill in blank
mediumComplete the code to exit the process with an error code 1.
Node.js
process.exit([1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 which means success.
Using exit codes outside the valid range 0-255.
✗ Incorrect
Exit code 1 usually means the process ended with an error.
3fill in blank
hardFix the error in the code to properly exit the process with code 2.
Node.js
process.exit = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning a number directly to process.exit.
Calling process.exit inside assignment without a function wrapper.
✗ Incorrect
You cannot assign a number to process.exit. Instead, assign a function that calls process.exit(2).
4fill in blank
hardFill both blanks to exit with code 3 after logging an error message.
Node.js
console.error('Error occurred'); process.[1]([2]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid method names like stop.
Passing wrong exit codes like 1 instead of 3.
✗ Incorrect
Use process.exit(3) to exit with code 3 after logging the error.
5fill in blank
hardFill all three blanks to exit with code 4 only if an error variable is true.
Node.js
if ([1]) { console.log('Exiting due to error'); process.[2]([3]); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using undefined variables in the condition.
Using invalid method names instead of exit.
Passing wrong exit codes.
✗ Incorrect
Check if error is true, then call process.exit(4) to exit with code 4.