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 Object-Oriented JavaScript Object Basics Dot Notation & Bracket Notation

Truman Smith
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Truman Smith
Full Stack JavaScript Techdegree Graduate 17,901 Points

I'm stuck on the first part of the challenge

Why does the challenge not accept this code?

const player1 = { name: 'Ashley', color: 'purple', isTurn: true, play: function(){ if ( this.isTurn ) { } } }

The statement "works" in the browser console, in that it doesn't throw a syntax error. I've tried variations of the if-statement that are functionally the same and haven't found the magic sequence that it wants.

======

Here is the challenge instructions: Inside the play method, write an empty if statement that checks if it's the players turn. Use dot notation.

Here is the error my answer returns: Bummer: Something is incorrect. Check that you wrote an if statement inside the method. Check that you're using dot notation. Are you using the this keyword?

4 Answers

Your code appears correct. All I did was remove the space before and after this.isTurn so you end up with (this.isTurn) and it passed.

Hello. How could I do the segond part of this question please. each time I do it, it doesn't work. It says:

Inside the if statement, return a string equal to the value of the name property followed by the string " is now playing!". Use bracket notation.

Dustin Wildes
Dustin Wildes
12,094 Points

const player1 = { name: 'Ashley', color: 'purple', isTurn: true, play: function(){ if (this.isTurn) { return(${player1['name']} is now playing!); } } }

I used template literal (using back ticks shared with the tilde mark) as show above. Maybe give that a try and let me know?

Marek Ostrowski
Marek Ostrowski
16,214 Points

play: function(){ if (this.isTurn) { return player1['name'] + " is now playing!"} }