0

我正在为我的 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 );
}

它应该只打印一个由变量 one 输入定义的字符串,但它会打印出所有字符串。

4

1 回答 1

1

您的 if 语句总是评估为真,因为

if (memberOfAAA === "yes" || "Yes" ... )

应该

if (memberOfAAA === "yes" || memberOfAAA === "Yes" ...)

此外,您应该使用 if/else if 语句。

于 2013-04-08T18:02:31.013 回答