Redux Road (Different "wagon" state)

So I am done with the Redux Road project but my final object values are different from the one from Codecademy.

This is my final wagon output:
{ supplies: 45, distance: 20, days: 6 }

This is the supposed correct output:
{
supplies: 5,
distance: 40,
days: 6
}

And this is my code:
const initialWagonState = {

supplies: 100,

distance: 0,

days: 0

};

const wagonReducer = (state = initialWagonState, action) => {

switch (action.type){

case 'gather': {

  return {

    ...state, 

    supplies: state.supplies + 15,

    days: state.days + 1

  };

};

case 'travel': {

  if (state.supplies <= 0){

    return state;

  } else {

    return {

    ...state,

    supplies: state.supplies - 20,

    distance: state.distance + 10,

    days: state.days + action.payload

    };

  };

};

case 'tippedWagon': {

  return {

    ...state,

    supplies: state.supplies - 30,

    days: state.days + 1

  };

};

default: {

return state;

};

};

};

let wagon = wagonReducer(undefined, {});

wagon = wagonReducer(wagon, {

type: ‘travel’,

payload: 1

});

wagon = wagonReducer(wagon, {

type: ‘gather’

});

wagon = wagonReducer(wagon, {

type: ‘tippedWagon’

});

wagon = wagonReducer(wagon, {

type: ‘travel’,

payload: 3

});

console.log(wagon);

Kindly assist me.

hi if you look at your travel case again it needs to be supplies -20 per days traveled and distance + 10 per days traveled
`` supplies: state.supplies - 20*action.payload,

distance: state.distance + 10*action.payload,

days: state.days + action.payload,

}

1 Like