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 trialHaardik Gupta
Full Stack JavaScript Techdegree Student 5,459 PointsIf else help
im being told to write an empty if statment that checks if student one is suppoesed play by checking if isTurn is true but for some reason im getting an error saying unexpected end of input
const player1 = {
name: 'Ashley',
color: 'purple',
isTurn: true,
play: function(){
if (player1.isTurn = true) {
}
}
4 Answers
Steven Parker
231,184 PointsHere's a few hints:
- when referring to instance attributes, use "this" instead of the variable name
- a single = is an assignment operator, that's not what you need in an "if" expression
- when testing a boolean value, you don't need to compare it to "true" — just name the value
Dimitar Dimitrov
11,800 PointsTo check if condition is true you need == operator not = and i believe the challenge wants you to use the this keyword to target the object property, fix these 2 steps and you will do it
Christopher Evans
9,896 PointsI tried this, but still no luck... I'm having the same problem as Haardik.
const player1 = {
name: 'Ashley',
color: 'purple',
isTurn: true,
play: function(){
// write code here.
if (this.isTurn == true) {
};
}
Kostatinos Yacoumakis
Full Stack JavaScript Techdegree Graduate 16,231 PointsYou have a colon in the wrong spot. Try resetting the challenge and adding everything from there. You are on the right track. Remember you don't need to set a boolean value to true in an if statement. You just need to name the value by itself for it to be true, if you wanted to set it to false it would look like if(!this.isTurn){ }
Haardik Gupta
Full Stack JavaScript Techdegree Student 5,459 Pointsi have fixed the code but am still getting
unexpected token function
const player1 = { name: 'Ashley', color: 'purple', isTurn: true, play function(){ if (this.isTurn) {
};
}
Steven Parker
231,184 PointsHaardik, I'm still seeing unbalanced braces (3 open, 2 close). And the colon after "play" seems to be missing now (I do not understand the colon comment Kostatinos made).
Kostatinos Yacoumakis
Full Stack JavaScript Techdegree Graduate 16,231 PointsMy mistake, I was actually looking at Christopher Evans code.
Haardik Gupta
Full Stack JavaScript Techdegree Student 5,459 PointsHaardik Gupta
Full Stack JavaScript Techdegree Student 5,459 Pointsi tried this
const player1 = { name: 'Ashley', color: 'purple', isTurn: true, play: function(){ if (player1.isTurn) { }
but i got unexpected identifier
Steven Parker
231,184 PointsSteven Parker
231,184 PointsIt looks like you have unbalanced braces here. And you still need to use "this" instead of the variable name.