Tell us what’s happening:
I’m confused on how this script isn’t passing the test cases. I’m retrieving the first 8 characters from the hex string using the .substring() method, so that I can then convert it to a decimal via the .parseInt() method with a radix of 16 (so that it can handle hex). I then use the Date() constructor followed by the toISOString() method to put it in the ISO 8601 string format
Your code so far
function mongoIdToDate(id) {
const subString = id.substring(0, 8);
const decimalValue = parseInt(subString, 16);
const dateValue = new Date(decimalValue);
id = dateValue.toISOString();
return id;
}
console.log(mongoIdToDate("6a094b50bcf86cd799439011"));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36
Challenge Information:
Daily Coding Challenge - Mongo ID Date
https://www.freecodecamp.org/learn/daily-coding-challenge/2026-05-17