For some reason when preview this code, It only outputs the bride\'s guest list
ID: 3771418 • Letter: F
Question
For some reason when preview this code, It only outputs the bride's guest list and not the groom's. Could someone point out what I could be doing wrong?
<script type="text/javascript">
<!--
var guestName, guestType, giftType, newGuest,brideAccum, groomAccum;
//assignments
brideCounter = 0;
groomCounter = 0;
var newGuest = "yes"
//starts loop
while (newGuest == "yes")
{
guestName = prompt("Enter Guest Name.", "");
guestType = prompt("Is This a Guest of the Bride or Groom?", "");
if (guestType == "groom")
{
groomCounter = groomCounter + 1;
if (groomCounter == 1)
{
groomAccum = "<p>Guest of the Groom: <br>" + groomCounter + "." +
guestName + giftType;
}
else
{
groomAccum = groomAccum + "<br>" + groomCounter + "." + guestName +
giftType;
}
}
else//guest is for the bride
{
brideCounter = brideCounter + 1;
if (brideCounter == 1)
{
brideAccum = "<p>Guests of the Bride: <br>" + brideCounter + "." +
guestName + giftType;
}
else
{
brideAccum = brideAccum + "<br>" + brideCounter + "." + guestName +
giftType;
}
}
newGuest = prompt("New Guest?","yes")
}
document.write(groomAccum);
document.write(brideAccum);
// -->
</script>
Explanation / Answer
//Modified code in bold letters
<script type="text/javascript">
<!--
var guestName, guestType, giftType, newGuest,brideAccum, groomAccum;
//assignments
brideCounter = 0;
groomCounter = 0;
var newGuest = "yes"
//starts loop
while (newGuest == "yes")
{
guestName = prompt("Enter Guest Name.", "");
giftType = prompt("Enter gift type.", "");
guestType = prompt("Is This a Guest of the Bride or Groom?", "");
if (guestType == "groom")
{
groomCounter = groomCounter + 1;
if (groomCounter == 1)
{
groomAccum = "<p>Guest of the Groom: <br> "+"<p> Name Gift<br>"+
+ groomCounter + "." +
guestName + giftType;
}
else
{
groomAccum = groomAccum + "<br>" + groomCounter + "." + guestName +
giftType;
}
}
else//guest is for the bride
{
brideCounter = brideCounter + 1;
if (brideCounter == 1)
{
brideAccum = "<p>Guests of the Bride: <br>" +
"<p> Name Gift<br>"+
brideCounter + "." +
guestName + giftType;
}
else
{
brideAccum = brideAccum + "<br>" + brideCounter + "." + guestName +
giftType;
}
}
newGuest = prompt("New Guest?","yes")
}
document.write(groomAccum);
document.write(brideAccum);
// -->
</script>
-------------------------------------------------------------------
Note: script working. Added prompt for gift variable and included in the bride and groom list
Sample output:
Guest of the Groom:
Name Gift
1.Groom1Makeupset
2.Groom2DiningSet
Guests of the Bride:
Name Gift
1.Bride1TV
2.Bride2Phone