Copy an Object with Object.assign help

Tell us what’s happening:

I’m stuck. I need help please.

Your code so far


const defaultState = {
  user: 'CamperBot',
  status: 'offline',
  friends: '732,982',
  community: 'freeCodeCamp'
};

const immutableReducer = (state = defaultState, action) => {
  switch(action.type) {
    case 'ONLINE':
      // don't mutate state here or the tests will fail
      const newObject = Object.assign({}, {state.status}, { status: action.type})
      return newObject;
    default:
      return state;
  }
};

const wakeUp = () => {
  return {
    type: 'ONLINE'
  }
};

const store = Redux.createStore(immutableReducer);

I also tried:

const newObject = Object.assign({}, {state}, { status: 'ONLINE'})
 return newObject;

But nothing happens
Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/redux/copy-an-object-with-object-assign/

 const newObject = Object.assign({}, {state}, { status: action.type})
 return newObject;

I specified state as the source object here then I am trying to update the status to ‘ONLINE’ by typing { status: action.type}. is this correct?

state is an object, so you do not wrap it with { }

Also, why would you use action.type for the status property value? The instructions tell you the status property of state should be set to ‘online’ not ‘ONLINE’.

1 Like

Thank you, I passed the test. I thought that using action.type would return the needed string but I forgot that javascript is case sensitive.