Hi everybody. Help me with this, please.
Context: my code does not pass the test, but if I run it outside the project, it does what is requested.
handlers.js file:
import { updateGold } from './functions.js'
export const handleKeyPress = (term, state) => {
return (name, matches,data) => {
const s = String.fromCharCode(data.code);
const lg = Object.keys(state.producers).length;
const index = state.producers.map(object => object.id).indexOf(s);
if(s === 'G' || s === 'g') {
++state.gold;
updateGold(term, state);
}
// #### TESTED OUTSIDE PROJECT ###
state.producers.find(object => {
if(object.id === s && state.gold >= object.cost) {
// Deduct the cost of the producer from the gold balance
state.gold = state.gold - object.cost;
// Increment the count of the producer that was purchased
++state.producers[index].count;
// Increase the cost of the next producer by multiplying the current cost by the growthRate
if(index+1 < lg) {
cnp = state.producers[index+1];
cnp.cost = cnp.cost * cnp.growthRate;
}
updateGold(term, state);
}})
// #### TESTED OUTSIDE PROJECT ###
}}