基本Javascript if/else-我做错了什么?
我绞尽脑汁想了几个小时,但我被卡住了,有人要我什么吗?我做错了什么基本Javascript if/else-我做错了什么?,javascript,Javascript,我绞尽脑汁想了几个小时,但我被卡住了,有人要我什么吗?我做错了什么 function exerciseThree(typeOfPizza){ let lovesPizza; // In this exercise, you will be given a variable, it will be called: typeOfPizza // You are also given another variable called: lovesPizza; // Using an
function exerciseThree(typeOfPizza){
let lovesPizza;
// In this exercise, you will be given a variable, it will be called: typeOfPizza
// You are also given another variable called: lovesPizza;
// Using an if/else statement assign lovesPizza to true if typeOfPizza is 'pepperoni', assign it to false if it is 'olives'
if (typeOfPizza === 'pepperoni');
lovesPizza = true;
} else {
(typeOfPizza === 'olives');
lovesPizza = false;
}
// Please write your answer in the line above.
return lovesPizza;
}
这只是你的“如果”语法
函数练习三(Pizza类型){
让爱斯皮扎;
//在本练习中,您将获得一个变量,它将被称为:typeOfPizza
//你也会得到另一个变量:lovesPizza;
//如果Pizza的类型为“pepperoni”,则使用if/else语句将lovesPizza赋值为true;如果Pizza的类型为“olives”,则将其赋值为false
if(Pizza的类型=='pepperoni'){
lovesPizza=正确;
}else if(typeOfPizza==='olives'){
lovesPizza=假;
}
//请在上面一行写下你的答案。
回到斯皮扎;
}
在if语句中,分号似乎放错了位置。对于基本if语句,分号仅在条件为true(大括号之间的部分)时位于要执行的代码块中的行之后,而不是在条件本身之后:
if (condition) { //no semicolon
// block of code to be executed if the condition is true - semicolon here
}
因此,您的代码基本上有两个额外的分号和两个右大括号,而没有匹配的右大括号。为您的代码尝试以下操作:
function exerciseThree(typeOfPizza){
let lovesPizza;
// In this exercise, you will be given a variable, it will be called: typeOfPizza
// You are also given another variable called: lovesPizza;
// Using an if/else statement assign lovesPizza to true if typeOfPizza is 'pepperoni', assign it to false if it is 'olives'
if (typeOfPizza === 'pepperoni'){
lovesPizza = true;
} else if (typeOfPizza === 'olives'){
lovesPizza = false;
}
// Please write your answer in the line above.
return lovesPizza;
}
您可以查看此页面以了解更多详细信息:
else{(typeOfPizza=='olives');lovesPizza=false;}
->如果(typeOfPizza=='olives'){lovesPizza=false;}
尝试在测试后删除分号(typeOfPiza=='olives'),您的花括号不正确,您的条件后面有分号,不应该在那里,带有附加条件的else
应该是else if(condition)
。