请告诉我如何解决,答案是“对象未定义”。
var dog = {
name : "Fido",
weight : 20.2,
age : 4,
breed : "mixed",
activity : "fetch balls"
};
var bark;
if (dog.weight > 20) {
bark = "WOOF WOOF";
} else {
bark = "woof woof";
}
var speak = dog.name + " says " + dog.bark + " when he wants to " + dog.activity;
console.log(speak);
答案 0 :(得分:0)
如果要将其设置为bark = "..."
对象的属性,请将其设置为:
dog
。
dog.bark = "WOOF WOOF";
var dog = {
name: "Fido",
weight: 20.2,
age: 4,
breed: "mixed",
activity: "fetch balls"
};
if (dog.weight > 20) {
dog.bark = "WOOF WOOF";
} else {
dog.bark = "woof woof";
}
var speak = dog.name + " says " + dog.bark + " when he wants to " + dog.activity;
console.log(speak);