很抱歉再次打扰大家,但我的代码似乎还有另一个问题。它为某些输入输出相同的结果,我在过去 15 分钟左右试图找出问题所在。我会问我的导师,但我目前不在大学。
再次,代码在下面,感谢您抽出宝贵的时间来忍受我。
//declare vars and/or constants
var endString = "Total cost per night is $";
//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
//double yes
if(pplCount == "1" || pplCount == "2" && discYes == "Yes" && viewYes == "Yes") {
discount = 50*0.15;
roomCost = 50;
viewCost = (roomCost*0.10);
finalRoomCost = roomCost - discount + viewCost;
document.write(endString + finalRoomCost);
}
else if(pplCount === "3" || pplCount === "4" && discYes == "Yes" && viewYes == "Yes") {
discount = 60*0.10;
roomCost = 60;
viewCost = (roomCost*0.10);
finalRoomCost = roomCost - discount + viewCost;
document.write(endString + finalRoomCost);
}
else if(pplCount === "5" || pplCount === "6" && discYes === "Yes" && viewYes === "Yes") {
discount = 70*0.05;
roomCost = 70;
viewCost = (roomCost*0.10);
finalRoomCost = roomCost - discount + viewCost;
document.write(endString + finalRoomCost);
}
else if(pplCount === "1" || pplCount === "2" && discYes === "No" && viewYes === "Yes") {
discount = 50*0.15;
roomCost = 50;
viewCost = (roomCost*0.10);
finalRoomCost = roomCost + viewCost;
document.write(endString + finalRoomCost);
}
else if(pplCount === "3" || pplCount === "4" && discYes === "No" && viewYes === "Yes") {
discount = 60*0.10;
roomCost = 60;
viewCost = (roomCost*0.10);
finalRoomCost = roomCost + viewCost;
document.write(endString + finalRoomCost);
}
else if(pplCount === "5" || pplCount === "6" && discYes === "No" && viewYes === "Yes") {
discount = 70*0.05;
roomCost = 70;
viewCost = (roomCost*0.10);
finalRoomCost = roomCost + viewCost;
document.write(endString + finalRoomCost);
}
else if(pplCount === "1" || pplCount === "2" && discYes === "No" && viewYes === "No") {
finalRoomCost = 50;
document.write(endString + finalRoomCost);
}
else if(pplCount === "3" || pplCount === "4" && discYes === "No" && viewYes === "No") {
finalRoomCost = 60;
document.write(endString + finalRoomCost);
}
else if(pplCount === "5" || pplCount === "6" && discYes === "No" && viewYes === "No") {
finalRoomCost = 70;
document.write(endString + finalRoomCost);
}
else if(pplCount === "1" || pplCount === "2" && discYes === "Yes" && viewYes === "No") {
discount = 50*0.15;
roomCost = 50;
viewCost = (roomCost*0.10);
roomCost = roomCost - discount;
document.write(endString + finalRoomCost);
}
else if(pplCount === "3" || pplCount === "4" && discYes === "Yes" && viewYes === "No") {
discount = 60*0.10;
roomCost = 60;
finalRoomCost = roomCost - discount;
document.write(endString + finalRoomCost);
}
else if(pplCount === "5" || pplCount === "6" && discYes === "Yes" && viewYes === "No") {
discount = 70*0.05;
roomCost = 70;
finalRoomCost = roomCost - discount;
document.write(endString + finalRoomCost);
}