Hello, code seems to be doing what's expected, yet, the following errors are appearing in the status of the task when submitted:
code is:
Hello, code seems to be doing what's expected, yet, the following errors are appearing in the status of the task when submitted:
code is:
CristianB I can't retype all your code, please post it as text.
import { updateGold } from "./functions.js";
export const handleKeyPress = (term, state) => {
return (name, matches, data) => {
let k = String.fromCharCode(data.code);
switch (k) {
case 'g':
state.gold++;
break;
case 'G':
state.gold++;
break;
case '1':
state.gold=state.gold-state.producers[0].cost;
state.producers[0].cost=state.producers[0].cost*state.producers[0].growthRate;
state.producers[0].count++
break;
case '2':
state.gold=state.gold-state.producers[1].cost;
state.producers[1].cost=state.producers[1].cost*state.producers[1].growthRate;
state.producers[1].count++
break;
case '3':
state.gold=state.gold-state.producers[2].cost;
state.producers[2].cost=state.producers[2].cost*state.producers[2].growthRate;
state.producers[2].count++
break;
default:
break;
}
// if (k =='g' || k == 'G') {
// }
updateGold(term,state);
}
}
CristianB rewrite handleKeyPress
to make sure it works with any numeric id, not just 1, 2, 3.
got it, thanks.
help needed here
import { updateGold } from "./functions.js";
export const handleKeyPress = (term, state) => (name, matches, data) => {
const keyPress = String.fromCharCode(data.code);
if(keyPress === "g" || keyPress === "G"){
state.gold++;
}else {
for (let i = 0; i < config.producers.length; i++) {
if((keyPress === config.producers[i].id) && (config.gold >= config.producers[i].cost)){
config.gold = config.gold - config.producers[i].cost;
config.producers[i].cost *= config.producers[i].growthRate;
config.producers[i].count += 1;
}
continue;
}
}
updateGold(term,state);
}
prodigy197 what's your question? Usually, it's best to create a new topic for each issue. Then describe it in detail, so that it's clear what's your problem.