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 trialAshi A
2,531 PointsNot 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
231,269 PointsYou 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 React.PropTypes.string.isRequired
Sanjeev Veloo
4,713 PointsI 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
231,269 PointsA comma would be placed between items, but not after the last item.
Henrik Boelsmand
11,395 PointsI 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
231,269 PointsSome 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
11,395 PointsTrailing 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
231,269 PointsI 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?
Ashi A
2,531 PointsAshi A
2,531 Points:facepalm: Doh!
Thank you, Steven.