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 Filling Out the Play Method

Answer for Challenge Task 1 of 2?

I don't understand why this answer isn't working, if I run it in the console it evaluates correctly with no syntax errors? It's pretty frustrating to get stuck on things like this without better hints and not be able to move forward.

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

2 Answers

Alex Koumparos
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,887 Points

Hi Jon,

Looks like the challenge interpreter is being really fussy. I pasted your code into the challenge and had to make two changes.

First, I had to remove the space between the opening parenthesis and this. I'm not sure why this was necessary, maybe there is linter rule behind the scenes that requires no spaces between open parens and a statement.

Second, I had to remove the unnecessary === true. Remember that a JavaScript condition wants a boolean expression. Something like x === 5 is a boolean expression because it evaluates to true or false. In the case of isTurn, it already is boolean (true) so you don't need to compare it to anything to make it evaluate to a boolean value. Any time you have a boolean-type value (let's say it's in the variable myBool) you can write an if expression as follows:

if (myBool) {
   // do something
}

It still seems unreasonable for the challenge parser to fail the code though, since the === true, while redundant, isn't invalid syntax.

Hope that helps

Alex

Sam Gord
Sam Gord
14,084 Points

your code looks ok to me too , maybe try writing the if statement a little more minimal like this -->

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

hope it works! :-? :D