0

i tried a tutorial from their site and i encountered this error and i dont know what is wrong. This is the code:

function formatName(user) {
        return user.firstName + ' ' + user.lastName; //this is line 16
      }

      const user = {
        firstName: 'Ciofliceanu';
        lastName: 'Serban';
      };

      const element = <h1>Hello, {formatName(user)}</h1>;

      ReactDOM.render(element, document.getElementById('root'));

I expect the output to be Hello, Ciofliceanu Serban but the output is: ./src/App.js Line 16: Parsing error: Unexpected token

6
  • 1
    Have you tried replacing the semicolons in the definition of user with commas? Commented Jan 11, 2019 at 21:58
  • @ChristianIvicevic you added this comment seconds before I posted my answer. If you want to post an answer, I can take my down. Commented Jan 11, 2019 at 22:01
  • 1
    @AlexanderStaroselsky Don't worry, thanks for being considerate. Sometimes SO can be rough :D Commented Jan 11, 2019 at 22:02
  • Really you should just flag it as a typo. Commented Jan 11, 2019 at 22:51
  • I replaced semicolons with comas and still same error...other ideas ? Commented Jan 12, 2019 at 7:08

1 Answer 1

2

The error is most likely really happening at definition of user as this is not a proper object literal:

const user = {
  firstName: 'Ciofliceanu';
  lastName: 'Serban';
};

Try replacing the ; with ,:

const user = {
  firstName: 'Ciofliceanu',
  lastName: 'Serban'
};

Hopefully that helps!

Sign up to request clarification or add additional context in comments.

2 Comments

Hello, i modified like you said and it still shows the same error...any idea ?
You need to provide more information regarding the configuration of your application. It’s not clear how/where you are compiling/running this. Did you use Create React App?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.