With the code given below, I'm trying to output the value and type of choc and I'm getting undefined for type and milk for chocolate. Can someone please help me understand how to output the type? I've been working on this for awhile and it's not clicking to me. Thanks!
// we set up a base class
function Candy() {
this.sweet = true;
}
// create a "Chocolate" class with a "type" argument
Chocolate = function(type){
this.type = type;
};
// say that Chocolate inherits from Candy
Chocolate.prototype = new Candy();
// create a "choc" object using the Chocolate constructor
// that has a "type" of "milk"
var choc = new Object();
choc.type = "milk";
// print the sweet and type properties of choc
console.log(choc.sweet);
console.log(choc.type);
//////this is what I changed it to and still doesnt work//////////
// we set up a base class
function Candy() {
this.sweet = true;
}
// create a "Chocolate" class with a "type" argument
Chocolate = function(type){
this.type = type;
};
// say that Chocolate inherits from Candy
Chocolate.prototype = new Candy();
// create a "choc" object using the Chocolate constructor
// that has a "type" of "milk"
var choc = new Chocolate();
choc.type = "milk";
// print the sweet and type properties of choc
console.log(choc.sweet);
console.log(choc.type);
Objectconstructor but say you would use theChocolateconstructor?.value.true, and thenmilk.