Redux Road Project

Hello world, I have a problem with the Redux Road project. Basically, I wrote all the code by following the instruction given, but I have a different output.

Link to the project: https://www.codecademy.com/paths/full-stack-engineer-career-path/tracks/fscp-redux/modules/core-concepts-in-redux/projects/redux-road-core-concepts

On task 11 of Redux Road, I am stuck. The value that I get is different from the instruction given which needs:

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

This is my code →

And the output that I got from my code:

{ supplies: 100, distance: 0, days: 0 }
{ supplies: 80, distance: 10, days: 1 }
{ supplies: 95, distance: 10, days: 2 }
{ supplies: 65, distance: 10, days: 3 }
{ supplies: 45, distance: 20, days: 6 }

task 5 says:

  • 20 less supplies for each day
  • 10 more kilometers of distance traveled for each day

which means on your code

case “travel”: {
return {
…state,
supplies: state.supplies - 20,
distance: state.distance + 10,
days: state.days + action.payload,
}
}

you need to include that 'each day ’

I did :

case “travel”: {
return {
…state,
supplies: state.supplies - 20action.payload,
distance: state.distance + 10
action.payload,
days: state.days + action.payload,
}
}

(sorry I realised Codecademy removed (*) between 10 and action.payload :slight_smile:

hope this helps :slight_smile:

4 Likes

Thank you so much :smiling_face_with_three_hearts:, my first solution to this was adding a conditional statement on case "travel" lmao.

1 Like

thanks , very helpful

Completed with additional tasks.

Noticed that you must use a '’ operator for action.payload in case you want to ‘buy’ multiple supplies at once, payload acts like it’s 1 if you don’t.

So happy that I found this project very achievable compared to others :smiley:

any feedback is welcome!

You have logic mistake in “case ‘travel’”. You set “if (state.supplies < 20)”. That means that if you log:

wagon = reducer(wagon, {type: ‘travel’, payload: 1});
wagon = reducer(wagon, {type: ‘gather’});
wagon = reducer(wagon, {type: ‘tippedWagon’})
wagon = reducer(wagon, {type: ‘travel’, payload: 5});

The output will be: { supplies: -35, distance: 60, days: 8, cash: 200 }. Because at the moment when it comes to iterate"if", supplies = 65, but “state.supplies - (20 * action.payload)” = 100. That means that at that moment if = true.

Hint gives us an idea to use payload to calculate “if”. Possible solution is to set “if (state.supplies - (20 * action.payload) < 0)”.