我只需要有禮物的人的姓名輸出多個禮物。 例如:多個烤麪包機通過:jack and jill 繼承人我的代碼:感謝您的幫助。我的循環工作,但不是我的結尾,如果聲明。迷茫......我不知道如何寫這個「如果陳述」
<script type="text/javascript">
var guest = "yes"
var gift, side, yourName, kind, groomNameAccum, brideNameAccum;
var toaster, silverware, stemware, giftType;
var noGift = 0;
var groomCounter = 0;
var brideCounter = 0;
kind = parseInt(kind);
//initalizing loop
weddingGift = "yes"
//start loop
while (guest == "yes") {
side = prompt("Which side are you on? groom or bride?", "")
yourName = prompt("Whats your name?", "");
kind = prompt("What kind of gift?", "");
if (side == "groom") {
groomCounter = groomCounter + 1;
if (groomCounter == 1) {
groomNameAccum = "Groom side: <br>" + groomCounter + ". " + yourName + ": " + kind;
} else {
groomNameAccum = groomNameAccum + "<br>" + groomCounter + ". " + yourName + ": " + kind;
}
} else
if (side == "bride") {
brideCounter = brideCounter + 1;
if (brideCounter == 1) {
brideNameAccum = "<p>Bride side: <br>" + brideCounter + ". " + yourName + ": " + kind;
} else {
brideNameAccum = brideNameAccum + "<br>" + brideCounter + ". " + yourName + ": " + kind;
}
}
if (kind > 1) {
giftType = toaster + silverware + stemware;
} else {
giftType = noGift;
}
guest = prompt("Are there anymore guests?", "yes");
}
document.write(groomNameAccum);
document.write(brideNameAccum);
document.write("<p>Multiples Toasters by:<br>" + giftType + yourName + "<br/>");
document.write("Multiples Silverware by:<br>" + gift + "<br/>");
document.write("Multiples Stemware by:<br>" + gift);
// -->
</script>
爲什麼在最後有'// - >'?它不像任何實際使用的瀏覽器不支持JavaScript ... – Doorknob
我複製並粘貼在那裏,當我添加四個空格時,我必須刪除它。對不起 –
在我看來,你沒有正式聲明,因爲它是一個'text'字段,你正在轉換爲'int'。因此,按照我相信你希望的方式進行這項工作是一個巨大的改變。如果你想獲得更多的幫助,請製作一個jsFiddle。謝謝 – abc123