我是一个初学者,试图想出这个编码的东西。 我无法正确注销。你能发现问题吗?
在字符串中的console.log行中,从$ -sign开始,代码不会改变颜色,因此它不会识别它。谢谢。
const car2 = {
brand: "Porsche",
getCarDescription: function(cost, year, color) {
console.log("This car is a ${this.brand}. The price is $${cost}. The year is ${year}. The color is ${color}.\n");
}
};
car2.getCarDescription(90000, 2013, "red");
这辆车是$ {this.brand}。价格是$$ {cost}。这一年是$ {year}。颜色是$ {color}。
=>未定义
答案 0 :(得分:0)
const car2 = { brand: "Porsche", getCarDescription: function(cost, year, color)
{
console.log(`This car is a ${this.brand}. The price is $${cost}. The year is ${year}. The color is ${color}.\n`); }
};
car2.getCarDescription(90000, 2013, "red");
您需要使用``而不是""使用$ {}
请仔细阅读以下文档,了解更多详情https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals