Redux Road (Different "wagon" state)

I am done with the Redux Road project but my final output/answer is different from the Codecademy output.

My output: { supplies: 45, distance: 20, days: 6 }

Codecademy output: { supplies: 5, distance: 40, days: 6 }

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);

1 Like

Yup. On the ol’ Codecademy trail I too have died of dysentery

Maybe it’s just a typo… because in step 4… If you read the hint they flubbed the spread operator with only two . . so it reads . . spread instead of . . .spread.

Now I’ve got to rustle these lines of code back into their pen and work on the bonus lines of code so we don’t got no outlaws travelling beyond their means. :cowboy_hat_face: YEE HAW

So in trying to figure out the bonus content I read re-read the directions and changed my code a little bit so ignore the extra output. We had the wrong field multipliers so to speak. Gotta avoid those snakey math bits :snake:

1 Like

That’s right, the output was as a result of the wrong multiplier.
I figured it out and it works fine.

Thanks for the feedback.

1 Like

I mean I kind of figured since the tag was from a while ago but in case there was a bad case of the “WHY IS THIS NOT EVEN WORKING ALREADY” I thought once I uncovered it I’d share.

1 Like