function myFavFood(food){
var msg = "";
if(food === "pizza")
msg = "I love " + food;
if (food === "hotpockets")
msg = food + " woo";
if (food !== "pizza" && food!== "hotpockets")
msg = "I have bad taste in foods";
return 'msg'
}
var pizza = myFavFood("pizza")
var hot pockets = myFavFood("hotpockets")
var not hot pizza = myFavFood();
console.log(pizza, hot pockets, anything)
答案 0 :(得分:1)
您不能在变量之间使用空格,例如:
// INVALID variable name
var hot pockets = "something";
// VALID variable names
var hotPockets = "something";
var hot_pockets = "something";
您可以找到更多信息和示例here
答案 1 :(得分:0)
变量不能有空格......消除那些,你的代码应该有效。
答案 2 :(得分:0)
删除变量之间的空格,例如var hot pockets
到var hotPockets
和var not hot pizza
到var notHotPizza
,会出现意外标识符错误。
var pizza = myFavFood("pizza")
var hotPockets = myFavFood("hotpockets")
var notHotPizza = myFavFood();
console.log(pizza, hotPockets, notHotPizza);
另外,请移除return 'msg'
到return msg
周围的单引号以返回消息,而不是字符串"msg"
。
return msg;