Got a build error, but it pased the test? Redux "Register a Store Listener"

Tell us what’s happening:
“Build error, open your browser console to learn more.” is what I got.
Your code so far


const ADD = 'ADD';

const reducer = (state = 0, action) => {
switch(action.type) {
  case ADD:
    return state + 1;
  default:
    return state;
}
};

const store = Redux.createStore(reducer);

// Global count variable:
let count = 0;

// Change code below this line
store.subscribe(count += 1);
// Change code above this line

store.dispatch({type: ADD});
console.log(count);
store.dispatch({type: ADD});
console.log(count);
store.dispatch({type: ADD});
console.log(count);
  **Your browser information:**

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

Challenge: Register a Store Listener

Link to the challenge:

The instructions say:

Write a callback function that increments the global variable count every time the store receives an action, and pass this function in to the store.subscribe() method.

You have:

store.subscribe(count += 1);

That is not a callback function. When I fix that, it passes without issue for me.

1 Like

Hmm… that’s weird that the test passes even though you didn’t follow the instructions.

1 Like

Yeah, odd. Notice with the wrong code it doesn’t output the console.log statements properly. That test could be written better.

2 Likes

I’ll bring up an issue on GitHub

2 Likes