only 1 ,3 and 6 are being passed and the rest are not succeeding, please help;
my function.js file is:
`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.eraseLineAfter();
term.bold.yellow(state.gold + " ");
state.gold += state.productionRate;
}
export const checkInitCompleted = (term, state) => {
term.clear();
term.moveTo(25, 2);
term('You can purchase producers by clicking the number button (1, 2, 3, ...)');
term.moveTo(25, 2);
term.eraseLineAfter();
term("GOLD: ${state.gold}");
term.moveTo(25, 2);
term.eraseLineAfter();
term("PRODUCTION RATE: ${state.productionRate}");
state.isProducerListUpdated = false;
}
export const updateProducerList = (term,state) => {
state.producers.foreach((object) => {
if(object.count > 0){
term.moveTo(1,5);
term('${object.title} : ${object.count} | Production Per Second : ${object.baseProduction.tofixed(1)} | Cost : ${object.cost.tofixed(1)} \n');
}
}
)
state.producers.forEach((object) => {
if(object.count === 0){
term.moveTo(1,5);
term('${object.title} : ${object.count} | Production Per Second : ${object.baseProduction.tofixed(1)} | Cost : ${object.cost.tofixed(1)} \n');
};
});
state.isProducerListUpdated = true;
}`
and handler.js:
`import { checkInitCompleted, updateGold, updateProducerList } from './functions.js'
export const handleKeyPress = (term, state) => {
return (name, matches, data) => {
//updateGold(term, state);
const key = String.fromCharCode(data.code);
if (key === 'g' || key === 'G') {
state.gold++;
}
state.producers.find(object => {
if(object.id === Number(key) && state.gold >= object.cost) {
++object.count;
state.gold -= object.cost;
object.cost *= object.growthRate;
state.productionRate += object.baseProduction;
updateProducerList(term,state);
}})
if(state.isInitCompleted === false){
state.producers.forEach(object => {
if(state.gold >= object.cost){
checkInitCompleted(term, state);
if(state.isProducerListUpdated ===false){
updateProducerList(term,state);
}
}
});
}
}
}
export const handleStateChange = (term,state) => {
return () => {
updateGold(term,state);
}
} `
@Coderslang_Master