“Workaround Explorer Issue”
Having an issue with the final part of the “Workaround Explorer” project. I’ve built a working “Format Number” function that returns identical values to the solution code. Yet when I use my code, the “Details” on the output DOM don’t load (it works with the solution code). The import/export syntax is the same for both functions.
Any ideas on why my function doesn’t work and the solution code does?
// my formatNumber function here
export const formatNumber = (number) => {
let stringNum = String(Math.floor(number))
let indexLength = stringNum.length - 1;
let cleanNum = ‘’;
for (i = indexLength; i >= 0; i–) {
if (((indexLength - i) % 3 === 0) && (i !== indexLength)) {
cleanNum = stringNum[i] + ‘,’ + cleanNum;
} else {
cleanNum = stringNum[i] + cleanNum;
}
}
return cleanNum;
}
// the solution code (this works)
export const formatNumber = number => {
let numStr = String(Math.floor(number));
for (let i = numStr.length - 3; i > 0; i -= 3) {
numStr = numStr.slice(0, i) + ‘,’ + numStr.slice(i);
}
return numStr;
}
//from the main.js file:
import {formatNumber} from ‘./modules/utilities.js’