Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript React Basics (retired) Thinking in Components Decomposing our Application

Brian Patrick
PLUS
Brian Patrick
Courses Plus Student 2,770 Points

Getting syntax error for Player.propTypes section. Help.

I get this in dev tools.

Unexpected token (30:6) 28 | 29 | Player.propTypes = {

30 | name: React.PropTypes.string.isRequired, | ^ 31 | score: React.PropTypes.number.isRequired, 32 | } 33 |

function Player(props) {
  return(
  <div className="player">
    <div className="player-name">
    {props.name}
    </div>
    <div className="player-score">
      <div className="counter">
        <button className="counter-action decrement"> - </button>
          <div className="counter-score"> {props.score} </div>
        <button className="counter-action increment"> + </button>
      </div> 
    </div>
  );
}

Player.propTypes = {
  name: React.PropTypes.string.isRequired,
  score: React.PropTypes.number.isRequired,
}
Brian Patrick
Brian Patrick
Courses Plus Student 2,770 Points

I commented out the Player.propTypes object and I get the same errors with

Application.propTypes = {
  title: React.PropTypes.string,
};

The code was working before I added the Player function.

1 Answer

Andrew Hickman
seal-mask
.a{fill-rule:evenodd;}techdegree
Andrew Hickman
Full Stack JavaScript Techdegree Student 10,013 Points

Hey there Brian! You are getting a syntax error because <div className="player-score"> is not closed. React is attempting to render invalid JSX. Simply add a closing tag:

function Player(props) {
  return(
  <div className="player">
    <div className="player-name">
    {props.name}
    </div>
    <div className="player-score">
      <div className="counter">
        <button className="counter-action decrement"> - </button>
          <div className="counter-score"> {props.score} </div>
        <button className="counter-action increment"> + </button>
      </div> 

// CLOSE DIV.PLAYER-SCORE:
     </div>
    </div>
  );
}