Render with an If/Else Condition, what's wrong with my syntax?

Tell us what’s happening:
My code is working just fine, but the editor won’t let me even run the tests.
What’s wrong with my syntax here? I can’t find my typo.
I am getting the “error unexpected token” that chases the last character in the code. If I remove the } it will go to the next code over.
Help please

Your code so far


class MyComponent extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      display: true
    }
    this.toggleDisplay = this.toggleDisplay.bind(this);
  }
  toggleDisplay() {
    this.setState({
      display: !this.state.display
    });
  }
  render() {
    // change code below this line
 if (this.state.display === true) {
  return (
    <div>
      <button onClick={this.toggleDisplay}>Toggle Display</button>
      <h1>Displayed!</h1>
    </div>
  );
}
else {
  return (
    <div>
      <button onClick={this.toggleDisplay}>Toggle Display</button>
    </div>
  )
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36 OPR/63.0.3368.94.

Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/react/render-with-an-ifelse-condition

You have accidentally deleted a couple } which were present in the original seed code. If you indent your code, you would see it very quickly.

1 Like