texi rv texi rv - 2 months ago 11
Javascript Question

I tried to format my sportsPerson like first letter alone in caps

Can you tell me why the below error is happening. I tried to format my

sportsPerson
like first letter alone in caps. I am getting a syntax error. Can you tell me how to fix it. I am providing my code below.

/src/components/sports/tracker/sports-tracker-tile.jsx
Module build failed: SyntaxError: C:/workspace/basketball/src/components/sports/tracker/sports-tracker-tile.jsx: Unexpected token (80:76)


const sportsPerson = this.props.profile.firstName;
78 | return (
79 |


80 | {
Want some advice${sportsPerson && sportsPerson.length > 0 ?
,
<span style={{'text-transform': 'capitalize'}}>
${sportsPerson.toLowerCase()}
</span>`` : ''}?
}

Answer

I wouldn't suggest this approach, your ternary isn't formatted correctly which is causing the JS error. Instead I would use a variable like:

var playerName = sportsPerson || '';

var content = playerName ? <span style={{'text-transform': 'capitalize'}}>, {playerName.toLowerCase()}</span> 
: '';

and then in your h4 just do this.

<h4>Want some advice{content}?</h4>