Copy an Object with Object.assign looks like it should pass

Tell us what’s happening:
My console.log is giving me the correct answer from what I understand but it still won’t pass this test “should update the property status in state to online and should NOT mutate state.” Can anyone see why? Thank you.

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, action);
    newObject.status = action.type.toLowerCase();
    console.log(newObject);
    console.log(defaultState);
    return newObject;
    break;  
    default:
      return state;
  }
};

const wakeUp = () => {
  return {
    type: 'ONLINE'
  }
};
const store = Redux.createStore(immutableReducer);
//store.dispatch(wakeUp());

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36.

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

Good question. Let me take a look. By the way are you an author?

That did it for me. Thanks Randell.

In the realm of coding. Just curious.

I see you put your knowledge to work with your company. Thats cool.

// GET THE SOLUTION with A COOL EXPLANATION

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

// Create a new Object to let state be immutable,
//and yet to update the status key in it
const newObject = Object.assign({},state);

// Now change the value of status key in a cool way
newObject.status = ‘online’;

 return newObject;

default:
return state;
}
};

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

const store = Redux.createStore(immutableReducer);