How can I make the line inside the if statement work?
const player1 = {
name: "Ashley",
color: "purple",
isTurn: true,
play: function() {
if (this.isTrue) {
return `this["name"] is now playing`;
}
}
};
How can I make the line inside the if statement work?
const player1 = {
name: "Ashley",
color: "purple",
isTurn: true,
play: function() {
if (this.isTrue) {
return `this["name"] is now playing`;
}
}
};
Either make the property as isTrue or make the if statement variable check 'isTurn'.
For a start, the if statement won't be hit as isTrue isn't a vaiable in player1.
However:
const player1 = {
name: "Ashley",
color: "purple",
isTurn: true,
isTrue: true, // Do you need this?
play: function() {
if (this.isTrue) { // Or should this be "inTurn"?
console.log(this.name + " is now playing");
return this.name + " is now playing";
}
}
};
player1.play();
You can see this running here: https://jsfiddle.net/ohfu2kn6/
const player1 = {
name: "Ashley",
color: "purple",
isTurn: true,
play: function() {
if (this.isTrue) {
return this.name +" is now playing";
}
}
};