Copy an Object with Object.assign help

Copy an Object with Object.assign help
0.0 0

#1

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/


#2

The Object.assign first argument is the target object. All additional arguments are the source objects which you want to pass to the merge with the target object and should be actual arguments. {state.status} is not valid object syntax but {status: action.type} is.

You need to specify state as the source object. After the Object.assign, newObject will have all the same properties as state, which you can then modify and then return newObject.


#3
 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?


#4

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’.


#5

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.