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

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

#1

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/


#2

Why are you passing action as a source object?


#3

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


#4

That did it for me. Thanks Randell.


#5

Am I an author of what?


#6

In the realm of coding. Just curious.


#7

Not unless you count the thousands of responses I have given on the forum.


#8

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