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 Properties Review

Not sure why the Quiz marks this as incorrect (Properties Review Quiz in React)

Here's the quiz question to which the right answer that I typed in is " React.PropTypes.string "

function Player(props) {
  // …
}
Player.propTypes = {
  name: _________________

};  

Unfortunately, this answer is marked as incorrect. And I'm not sure why. Is my syntax off? Or is there something else that I'm missing?

https://facebook.github.io/react/docs/typechecking-with-proptypes.html

2 Answers

Steven Parker
Steven Parker
231,275 Points

You may have overlooked one of the requirements.

The question asks: "Fill in the code to ensure the property β€œname” is a required string for the Player Component:"

So the correct answer would be :point_right: React.PropTypes.string.isRequired

:facepalm: Doh!

Thank you, Steven.

Sanjeev Veloo
Sanjeev Veloo
4,713 Points

I had the same issue. What I did was I left out the comma at the end. But shouldn't the comma always be there?

I mean, in the video it's "React.PropTypes.string.isRequired,"

But when I used "React.PropTypes.string.isRequired" without the comma, it validated.

Weird!

Steven Parker
Steven Parker
231,275 Points

A comma would be placed between items, but not after the last item.

Henrik Boelsmand
Henrik Boelsmand
11,395 Points

I was wondering about this as well and I suppose it should allow both with and without comma on the last item. It depends on which version of JS/ECMAScript you are writing: http://eslint.org/docs/rules/comma-dangle

Steven Parker
Steven Parker
231,275 Points

Some versions might let you get away with some syntax errors. But it would be better to practice to write code that will run in all versions.

Henrik Boelsmand
Henrik Boelsmand
11,395 Points

Trailing commas in object literals are valid as per ECMAScript 5 and not a syntax error. Since the teacher uses them in the course it should be a valid answer for the quiz. However I get your point but that is a debate on when to adopt new features of the languages. In any case Babel would make it backwards compatible.

Steven Parker
Steven Parker
231,275 Points

I understand that newer engines allow it, and in ES6 you can even do that with function parameters. But it blurs the distinction between separators and delimitiers, and I don't personally consider it to be a good practice. It doesn't allow your code to do anything it wouldn't do the other way, so why break back-compatibility unnecessarily?