I'm trying to create a simple object with a method that changes the value of one of the keys. I want to initialize the isFoodWarm key to false, output the value, change it to true, then output it again. My expected output is false and then true, as the method should change it to true, but I am getting an error. I tried removing the parentheses from myBreakfast.heat();, which got rid of the error, but then it didn't successfully change the value. What am I doing wrong? Here is my code.
function Breakfast(food, drink, isFoodWarm) {
this.food = food,
this.drink = drink,
this.isFoodWarm = isFoodWarm,
heat = function() {
if (isFoodWarm === false){
isFoodWarm = true;
console.log("your food is now warm");
}
}
}
var myBreakfast = new Breakfast("english muffin", "OJ", "false");
console.log(myBreakfast.isFoodWarm);
myBreakfast.heat();
console.log(myBreakfast.isFoodWarm);
I get the following console output:
false
Uncaught TypeError: myBreakfast.heat is not a function