Why am I am getting the following error?
- formatNumber should be implemented according to the task description
Here is the functions.js file:
export const init = (term) => {
term('Welcome to the mining game!');
term.clear();
term.hideCursor();
term.grabInput();
}
export const updateGold = (term, state) => {
term.moveTo(25, 2);
term.bold.yellow(formatNumber(state.gold) + ' ');
term.eraseLineAfter();
state.gold += state.productionRate;
}
export const checkInitCompleted = (term, state) => {
term.moveTo(0, 1);
term.eraseLineAfter();
term('You can purchase producers by clicking the number button (1, 2, 3, ...)');
term.moveTo(0, 2);
term.eraseLineAfter();
term('GOLD:' + state.gold);
term.moveTo(0, 3);
term.eraseLineAfter();
term('PRODUCTION RATE:' + formatNumber(state.productionRate));
state.isProducerListUpdated = false;
}
export const updateProducerList = (term, state) => {
let j = 0;
let isOneZeroCountPrinted = false;
for (let i = 0; i < state.producers.length; i++) {
if (state.producers[i].count > 0 || (!isOneZeroCountPrinted && state.producers[i].count === 0)) {
term.moveTo(1, 5 + j);
term(`${state.producers[i].title}: ${state.producers[i].count} | Production per second: ${state.producers[i].baseProduction.toFixed(1)} | Cost: ${state.producers[i].cost.toFixed(1)}`);
term.eraseLineAfter();
if (state.producers[i].count === 0){
isOneZeroCountPrinted = true;
}
j++;
}
}
state.isProducerListUpdated = true;
}
export const formatNumber = (n) => {
if (n < 1000) {
return n.toFixed(1);
} else if (n < 1000000) {
return (n/1000).toFixed(2) + 'K';
} else if (n < 1000000000) {
return (n/1000000).toFixed(2) + 'M';
} else if (n < 1000000000) {
return (n/1000000000).toFixed(2) + 'B';
} else {
return (n/1000000000000).toFixed(2) + 'T';
}
}
Please help.