IDE Having Issues

Hi. I was attempting to do the task on here, but when I went to put
handleChange(event) { this.setState({ input: event.target.value }); }
it gives me this error:

SyntaxError: unknown: Unexpected token, expected ";" (8:24)

6 | };
7 | // change code below this line
8 | handleChange(event) {
| ^
9 | this.setState({
10 | input: event.target.value
11 | });
Any ideas?

Please post your full code. I suspect that you did not close a } or ).

“unexpected token” almost always means that you have mismatched quotes, parentheses, brackets, etc. The error is probably at or near line 8, position 24. It looks like your handleChange function probably doesn’t have it’s closing }, but that’s a guess without the code.

1 Like

My code:

class ControlledInput extends React.Component {

  constructor(props) {

    super(props);

    this.state = {

      input: ''

    };

    // change code below this line

      handleChange(event) {

      this.setState({

        input: event.target.value

      });

  };

    // change code above this line

  }

  // change code below this line

  // change code above this line

  render() {

    return (

      <div>

        { /* change code below this line */}

        { /* change code above this line */}

        <h4>Controlled Input:</h4>

        <p>{this.state.input}</p>

      </div>

    );

  }

};

Actually, that’s hard to read, so here’s a Pastebin: https://pastebin.com/2xhwj3bG

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Hello there,

Methods (handleChange) are not supposed to go within the constructor


For future posts, if you have a question about a specific challenge as it relates to your written code for that challenge, just click the Ask for Help button located on the challenge. It will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Hope this helps

2 Likes

image
Thank you! It works.