Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the os module in Node.js.
Node.js
const os = require([1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using other module names like 'fs' or 'http' instead of 'os'.
Forgetting to put quotes around the module name.
✗ Incorrect
The os module is imported using require('os') in Node.js.
2fill in blank
mediumComplete the code to get the system's hostname using the os module.
Node.js
const hostname = os.[1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
os.platform() which returns the OS platform, not hostname.Using
os.type() which returns the OS name.✗ Incorrect
The os.hostname() method returns the system's hostname.
3fill in blank
hardFix the error in the code to get the total system memory.
Node.js
const totalMem = os.[1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
os.freemem() which returns free memory, not total.Using non-existent methods like
os.memory() or os.getTotalMem().✗ Incorrect
The correct method to get total system memory is os.totalmem().
4fill in blank
hardFill both blanks to create an object with OS type and CPU architecture.
Node.js
const systemInfo = { type: os.[1](), arch: os.[2]() }; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up
os.platform() with os.type().Using
os.hostname() instead of os.arch() for CPU info.✗ Incorrect
os.type() returns the OS type and os.arch() returns the CPU architecture.
5fill in blank
hardFill all three blanks to create a summary string with platform, uptime, and user info.
Node.js
const summary = `Platform: ${os.[1]()}, Uptime: ${os.[2]()} seconds, User: ${os.userInfo().[3]`; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
os.type() instead of os.platform() for platform.Using
os.userInfo().name instead of username property.Confusing uptime with freemem or totalmem.
✗ Incorrect
os.platform() gives the platform, os.uptime() gives system uptime in seconds, and os.userInfo().username gives the current user's name.