Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
221,324 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
221,324 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
221,324 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
221,324 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?