Stuck on Redux: Write a Counter with Redux

Stuck on Redux: Write a Counter with Redux
0.0 0

#1
const INCREMENT = 'INCREMENT';
const DECREMENT = 'DECREMENT'; // define a constant for decrement action types

const defaultState = {
    number: 0
}

const counterReducer = (state = defaultState.number, action) => {
    switch (action.type) {
        case INCREMENT:
            let copy = Object.assign({},defaultState);
                return copy.number + 1;
                break;
        case DECREMENT:
            let copy2 = Object.assign({},defaultState);
                return copy2.number - 1; 
                console.log(defaultState.number) 
                break;   
         default: return state;
    }
   
}


const incAction = function(add) {
    return {
        type:INCREMENT
    }
}

const decAction = function(subtract) {
    return {
        type:DECREMENT
    }
}

const store = Redux.createStore(counterReducer);


I have looked at other solutions. I really wanted to make use of Object.assign property as mentioned in the redux documentation. What I am trying to do is make a shallow copy of the default state object and return a new state that will update the number property to the new value.


#2

somehow I managed to pass the test doing this

const INCREMENT = 'INCREMENT';
const DECREMENT = 'DECREMENT'; // define a constant for decrement action types

const defaultState = {
    number: 0
}

const counterReducer = (state = defaultState.number, action) => {
    switch (action.type) {
        case INCREMENT:
            let copy = Object.assign({},defaultState);
                return copy.number + 1;
                break;
        case DECREMENT:
            let copy2 = Object.assign({},defaultState);
            console.log(copy2.number-1) //This is the line that I added. 
                return copy2.number  //This is also another line that was modified. 
                break;   
         default: return state;
    }
   
}


const incAction = function(add) {
    return {
        type:INCREMENT
    }
}

const decAction = function(subtract) {
    return {
        type:DECREMENT
    }
}

const store = Redux.createStore(counterReducer);

what does console.log have to do with the solution to this challenge. Can anyone explain?


#3

semicolon after console missing?


#4

I solved it. Thanks for your input.


#5

Absolutely nothing. Delete that line and the code passes all the tests.


#6

i could have sworn it was not passing until I added that line and then it passed. I deleted that line and sure enough it still worked.

I swear I tried it without that line though.