我这里有点麻烦。我检查以确保我的变量只用数字定义,但代码仍然不是数字返回。有人知道我在做什么错吗?
下面的代码:
//declare vars and/or constants
var endString = "Total cost per night is $";
var viewCost;
var discount;
//input vars
pplCount = prompt("How many people will be staying?");
discYes = prompt("Do you have an AAA discount?");
viewYes = prompt("Do you want a room with a view?");
//if variables
if(pplCount === "1" || pplCount === "2" && discYes === "Yes" && viewYes === "Yes") {
discount = 50 * 0.15;
roomCost = 50;
roomCost = +roomCost - discount + viewCost;
viewCost = (+roomCost * 0.10);
document.write(endString + roomCost);
}else if(pplCount === "3" || pplCount === "4" && discYes === "Yes" && viewYes === "Yes") {
discount = 60 * 0.10;
roomCost = 60;
roomCost = roomCost - discount + viewCost;
viewCost = (roomCost * 0.10);
document.write(endString + roomCost);
}
else if(pplCount === "5" || pplCount === "6" && discYes === "Yes" && viewYes === "Yes") {
discount = 70 * 0.05;
roomCost = 70;
roomCost = roomCost - discount + viewCost;
viewCost = (roomCost * 0.10);
document.write(endString + roomCost);
}
else if(pplCount === "1" || pplCount === "2" && discYes === "No" && viewYes === "Yes") {
discount = 50 * 0.15;
roomCost = 50;
roomCost = roomCost + viewCost;
viewCost = (roomCost * 0.10);
document.write(endString + roomCost);
}
else if(pplCount === "3" || pplCount === "4" && discYes === "No" && viewYes === "Yes") {
discount = 60 * 0.10;
roomCost = 60;
roomCost = roomCost + viewCost;
viewCost = (roomCost * 0.10);
document.write(endString + roomCost);
}
else if(pplCount === "5" || pplCount === "6" && discYes === "No" && viewYes === "Yes") {
discount = 70 * 0.05;
roomCost = 70;
roomCost = roomCost + viewCost;
viewCost = (roomCost * 0.10);
document.write(endString + roomCost);
}
else if(pplCount === "1" || pplCount === "2" && discYes === "No" && viewYes === "No") {
discount = 50 * 0.15;
roomCost = 50;
viewCost = (roomCost * 0.10);
document.write(endString + roomCost);
}
else if(pplCount === "3" || pplCount === "4" && discYes === "No" && viewYes === "No") {
discount = 60 * 0.10;
roomCost = 60;
viewCost = (roomCost * 0.10);
document.write(endString + roomCost);
}
else if(pplCount === "5" || pplCount === "6" && discYes === "No" && viewYes === "No") {
discount = 70 * 0.05;
roomCost = 70;
viewCost = (roomCost * 0.10);
document.write(endString + roomCost);
}
else if(pplCount === "1" || pplCount === "2" && discYes === "Yes" && viewYes === "No") {
discount = 50 * 0.15;
roomCost = 50;
roomCost = roomCost - discount;
viewCost = (roomCost * 0.10);
document.write(endString + roomCost);
}
else if(pplCount === "3" || pplCount === "4" && discYes === "Yes" && viewYes === "No") {
discount = 60 * 0.10;
roomCost = 60;
roomCost = roomCost - discount;
viewCost = (roomCost * 0.10);
document.write(endString + roomCost);
}
else if(pplCount === "5" || pplCount === "6" && discYes === "Yes" && viewYes === "No") {
discount = 70 * 0.05;
roomCost = 70;
roomCost = roomCost - discount;
viewCost = (roomCost * 0.10);
document.write(endString + roomCost);
}
是因为我定义了 roomCost 两次吗?