Write a Simple Counter with React: what am I doing wrong?

Tell us what’s happening:
I checked every other post regarding this challenge and I still can’t spot why my code doesn’t work. It doesn’t even render anything at all, no buttons, no text, nothing.
What am I missing?

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.decrement.bind(this);
  this.reset = this.reset.bind(this);
    // change code above this line
  }
  // change code below this line
  increment() {
   this.setState({
     count: this.state.count + 1,
   })
  };
  decrement() {
   this.setState({
     count: this.state.count - 1,
   })
  };
  reset() {
   this.setState({
     count = 0,
   })
  };

  // 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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/react/write-a-simple-counter

Hi @VirginiaBalseiro

You’ve got a syntax error in your reset method. It should be:

this.setState({
  count: 0
})
1 Like

Make sure this.setState in your reset function has appropriate format for assignemnts in an object.

count : 0

There also shouldn’t be commas inside as well.

Oh my God :woman_facepalming:
thanks!!!

1 Like