I have created a listener and passed it to subscribe method, the test case is still failing

Tell us what’s happening:
Even after following the instructions and passing a listener function, the test case still fails saying There should be a listener function subscribed to the store using store.subscribe.
I have gone through the hint ,tried arrow and normal function.
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
function listener () {
count+=1;
}

store.subscribe (listener);
// 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 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36.

Challenge: Register a Store Listener

Link to the challenge:

That’s just whitespace before subscribe and parenthesis, removing it makes test pass.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.