我正在为我的JScript类做一些事情,我无法看到我的代码是如何打印document.write的多个实例的。有什么帮助吗?
memberNumber = prompt("How many people will be staying?");
memberOfAAA = prompt("Are the members part of AAA?");
roomView = prompt("Do you want a room with a view?");
Number(memberNumber);
if(memberOfAAA === "yes" || "Yes", memberNumber > 5 && memberNumber < 3, roomView === "yes")
{
roomCost = (costRoom12 - (costRoom12 * percent1)+(costRoom12 * viewCost));
document.write("Total cost per night is $" + roomCost );
}if (memberOfAAA === "yes" || "Yes", memberNumber > 5 && memberNumber < 3, roomView === "no" || "No")
{
roomCost = (costRoom12 - (costRoom12 * percent1));
document.write("Total cost per night is $" + roomCost );}
if(memberOfAAA === "no" || "No" , memberNumber > 5 && memberNumber < 3, roomView === "yes" || "Yes")
{
roomCost = (costRoom12 + (costRoom12 * viewCost));
document.write("Total cost per night is $" + roomCost );
}if(memberOfAAA === "no" || "No" , memberNumber > 5 && memberNumber < 3, roomView === "no" || "No")
{
roomCost = (costRoom12);
document.write("Total cost per night is $" + roomCost );
}
if (memberOfAAA === "yes" || "Yes", memberNumber > 5 && memberNumber < 3, roomView === "yes" || "Yes") {
roomCost = (costRoom34 - (costRoom34 * percent2) + (costRoom34 * viewCost));
document.write("Total cost per night is $" + roomCost );
}
if (memberOfAAA === "yes" || "Yes", memberNumber > 5 && memberNumber < 3, roomView === "no" || "No") {
roomCost = (costRoom34 - (costRoom34 * percent2));
document.write("Total cost per night is $" + roomCost );
}
if(memberOfAAA === "no" && memberNumber > 5 && memberNumber < 3, roomView === "yes" || "Yes") {
roomCost = (costRoom34 + (costRoom34 * viewCost));
document.write("Total cost per night is $" + roomCost );
}
if(memberOfAAA === "no" || "No", memberNumber > 5 && memberNumber < 3, roomView === "no" || "No") {
roomCost = costRoom34;
document.write("Total cost per night is $" + roomCost );
}
if(memberOfAAA === "Yes" || "yes", memberNumber > 7 && memberNumber < 4, roomView === "yes" || "Yes") {
roomCost = (costRoom56 - (costRoom56 * percent3) + (costRoom56 * viewCost))
}
if(memberOfAAA === "yes" || "Yes", memberNumber > 7 && memberNumber < 4, roomView === "no" || "No") {
roomCost = (costRoom56 - (costRoom56 * percent3));
document.write("Total cost per night is $" + roomCost );
}
if(memberOfAAA === "no" || "No", memberNumber > 7 && memberNumber < 4, roomView === "yes" || "Yes") {
roomCost = (costRoom56 + (costRoom56 * viewCost));
document.write("Total cost per night is $" + roomCost );
}
if(memberOfAAA === "no" || "No", memberNumber > 7 && memberNumber < 4, roomView === "no" || "No") {
roomCost = (costRoom56);
document.write("Total cost per night is $" + roomCost );
}
它应该只打印一个输入变量所定义的字符串,但它会打印出所有字符串。
答案 0 :(得分:1)
您的if语句总是评估为true,因为
if (memberOfAAA === "yes" || "Yes" ... )
应该是
if (memberOfAAA === "yes" || memberOfAAA === "Yes" ...)
此外,您应该使用if / else if语句。