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 trialZak Mosbacher
Full Stack JavaScript Techdegree Graduate 16,080 PointsIs there a bug or something because i see no error in this :(
Why isnt this working, thanks for the help
const player1 = {
name: 'Ashley',
color: 'purple',
isTurn: true,
play: function(){
if(this.isTurn){
let string = this[0] +' is now playing!;
return string;
}else{
}
}
}
1 Answer
Jason Anders
Treehouse Moderator 145,860 PointsHey Zak,
You're really close. There are just a couple of things.
- First, there is a missing closing quote for your string.
- Second, the instruction state to
"return a string equal to the value of the name property"
, but for some reason you have an integer being passed into the bracket notation. I think you're trying to use an index, but the actualkey
name needs to be used.
Instead ofthis[0]
, you needthis["name"]
.
Also, just a quick tip for DRY code:
Instead of declaring a new variable and storing the concatenated string, then returning the variable. You can just return the string being concatenated.
let nameOfString = variable["keyName"] + " is going to print out a line.";
return nameOfString;
The DRY way would be:
return variable["keyName"] + " is going to print out a line.";
Both will result in identical output.
Anyway, hope that helps.
Nice work!! :)