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 trialTruman Smith
Full Stack JavaScript Techdegree Graduate 17,901 PointsI'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
KRIS NIKOLAISEN
54,971 PointsYour 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.
Truman Smith
Full Stack JavaScript Techdegree Graduate 17,901 PointsYes! That works.
Thank you Kris!
Makenson Duperval
7,028 PointsHello. 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
12,094 Pointsconst 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
16,754 Pointsplay: function(){ if (this.isTurn) { return player1['name'] + " is now playing!"} }