Challenge - 5 Problems
Path Extname Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
What is the output of path.extname for a simple file?
Given the following Node.js code using
path.extname, what will be printed to the console?Node.js
import path from 'path'; console.log(path.extname('photo.jpg'));
Attempts:
2 left
💡 Hint
Remember,
path.extname returns the extension including the dot.✗ Incorrect
The path.extname function returns the file extension including the dot. For 'photo.jpg', it returns '.jpg'.
❓ Predict Output
intermediate1:30remaining
What does path.extname return for a file with multiple dots?
What will be the output of this code snippet?
Node.js
import path from 'path'; console.log(path.extname('archive.tar.gz'));
Attempts:
2 left
💡 Hint
The extension is the substring after the last dot.
✗ Incorrect
path.extname returns the substring from the last dot to the end. For 'archive.tar.gz', it returns '.gz'.
❓ Predict Output
advanced1:30remaining
What is the output of path.extname for a hidden file?
Consider this code. What will it print?
Node.js
import path from 'path'; console.log(path.extname('.env'));
Attempts:
2 left
💡 Hint
Hidden files start with a dot but may not have an extension.
✗ Incorrect
Files like '.env' start with a dot but have no extension after that. path.extname returns an empty string.
❓ Predict Output
advanced1:30remaining
What does path.extname return for a directory path ending with a dot?
What will this code output?
Node.js
import path from 'path'; console.log(path.extname('/folder.name/.hiddenfile'));
Attempts:
2 left
💡 Hint
The extension is based on the last part of the path, not directories.
✗ Incorrect
The last part is '.hiddenfile' which starts with a dot but has no extension after it, so path.extname returns an empty string.
❓ Predict Output
expert2:00remaining
What is the output of path.extname for a filename with trailing dot?
Analyze this code and choose the correct output:
Node.js
import path from 'path'; console.log(path.extname('filename.'));
Attempts:
2 left
💡 Hint
The extension includes the last dot and characters after it, even if empty.
✗ Incorrect
When the filename ends with a dot, path.extname returns the dot as the extension.