-1

再度ご迷惑をおかけして申し訳ありませんが、コードに別の問題があるようです。一部の入力に対して同じ結果が出力されており、過去 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);
}
4

2 に答える 2