Decrement not working the way it should

Tell us what’s happening:
my decrement is adding to the count instead of subtract, it wont allow me to pass the challenge.

Your code so far


class Counter extends React.Component {
constructor(props) {
  super(props);
  this.state = {
    count: 0
  };
  // Change code below this line
  this.increment = this.increment.bind(this);
  this.decrement = this.increment.bind(this);
  this.reset = this.reset.bind(this);
  
  // Change code above this line
}
// Change code below this line
reset(){
    this.setState({
      count: 0
    });
  }

  increment(){
    this.setState(state =>({
      count: state.count + 1
    }));
  };

  decrement(){
    this.setState(state =>({
      count: state.count - 1
    }));
  };
// Change code above this line
render() {
  return (
    <div>
      <button className='inc' onClick={this.increment}>Increment!</button>
      <button className='dec' onClick={this.decrement}>Decrement!</button>
      <button className='reset' onClick={this.reset}>Reset</button>
      <h1>Current Count: {this.state.count}</h1>
    </div>
  );
}
};

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0.

Challenge: Write a Simple Counter

Link to the challenge:

you may have copied and pasted the above line without changing anything

thank you :sweat_smile:, its always something small

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