I don't get it why am I having the error ? Here is my Handlers.js

import { updateGold, checkInitCompleted, updateProducerList } from "./functions.js";



export const handleKeyPress = (term, state) => {
    return (name, matches, data) => {
        const key = String.fromCharCode(data.code);
        if (key === 'g' || key === 'G') {
            state.gold++
        }
        

        for (let i = 0; i<state.producers.length; i++) {
            if (key === `${state.producers[i].id}` && state.gold >= state.producers[i].cost) {
                state.gold -= state.producers[i].cost
                state.producers[i].cost *= state.producers[i].growthRate
                state.producers[i].count++
                state.productionRate+=state.producers[i].baseProduction
                state.isProducerListUpdated = false
            }

        }  
    for (const q in state.producers) {
        if (state.producers[q].count > 0 && state.isProducerListUpdated === false ) {
            term.moveTo(25, 3);     
            term.green(state.productionRate.toFixed(2));
        }
    }

    if (state.gold >= state.producers[0].cost && !state.isInitCompleted) {
        checkInitCompleted(term, state)   
    } 
    if (state.isProducerListUpdated == false) {
        updateProducerList(term, state)
    }
        
        
    }
    
}



export const handleStateChange = (term, state) => {
    return () =>  updateGold(term, state)
}

    Coderslang_Master
    TASK:
    It'd be very useful for the user to see the current production rate of their mining empire.
    Let's display it on the third line in green color (term.green()). Right under the current amount of gold.
    As we need to update this number only when we purchase the new producer, you can add the necessary code into handleKeyPress
    CHECKLIST:
    1) (ERROR) handleKeyPress should call term.moveTo(25, 3) if a new producer was purchased
    2) (DONE) handleKeyPress should update the productionRate in green
    3) (DONE) handleKeyPress should not print the current productionRate if no producer was purchased
    it works as expected though, don't know why the error occurs

      Coderslang_Master

      **CONSTANTS**
      import terminalKit from 'terminal-kit';
      export const term = terminalKit.terminal;
      export const config = {
          gold: 0,
          productionRate: 0,
          producers: 
          [
              {id: 1, title: 'Miner', cost: 10, growthRate: 1.13, baseProduction: 0.1, count: 0},
              { id: 2, title: 'Adventurer', cost: 100, growthRate: 1.17, baseProduction: 1, count: 0 },
              { id: 3, title: 'Professional', cost: 1200, growthRate: 1.14, baseProduction: 9, count: 0 }
          ],
          isInitCompleted: false,
          isProducerListUpdated: true
      
      }
      
      **FUNCTIONS**
      export const init = (term) => {
        term.clear();
        term.hideCursor();
        term.grabInput();
        term.bold.green('Welcome to the mining game!')
      }
      
      export const updateGold = (term, state) => {
        term.moveTo(25, 2)
        term.bold.yellow(state.gold.toFixed(2) + '   ')
        term.eraseLineAfter()
        state.gold += state.productionRate 
      
      }
      export const checkInitCompleted = (term, state) => {
        state.isInitCompleted = true
        state.isProducerListUpdated = false
        term.moveTo(1, 1)
        term.eraseLineAfter()
        term('You can purchase producers by clicking the number button (1, 2, 3, ...)')
        term.moveTo(0, 2)
        term.bold.yellow(`GOLD:`)
        term.moveTo(0, 3)
        term.bold.green(`PRODUCTION RATE: `)
      }
      
      export const updateProducerList = (term, state) => {
        term.moveTo(1, 5)
        for (const j in state.producers) {
          if (state.producers[j].count >= 0) {
            term( `${state.producers[j].title}: ${state.producers[j].count} | Production per second: ${state.producers[j].baseProduction.toFixed(1)} | Cost: ${state.producers[j].cost.toFixed(1)} ` )
          } else {
          term(`${state.producers[j].title}: ${state.producers[j].count} | Production per second: ${state.producers[j].baseProduction.toFixed(1)} | Cost: ${state.producers[j].cost.toFixed(1)} `)
          }
        }
        state.isProducerListUpdated = true
      }
      **GAME ENGINE**
      import { init } from './functions.js'
      import { handleKeyPress, handleStateChange} from './handlers.js'
      
      export const startMiningGame = (term, state) => {
        init(term)
        term.on('key', handleKeyPress(term, state))
         setInterval(handleStateChange(term, state), 1000);
      }
      
      **SOLUTION**
      import { startMiningGame } from './gameEngine.js'
      import { term, config } from './constants.js'
      startMiningGame(term, config) 

        tavbulaevr our tests didn't have a mock for term.bold.green. The issue will be fixed in about 15 minutes. Resubmit the task and let me know if it helped.

          Write a Reply...