So I've restarted my While-loop program and now am getting all NaN or they aren't saving the text I input

147 views Asked by At

I need to write a program for a wedding planner. They wish to create a gift registry for each couple. They want the gifts broken down by the whether the gift giver is on the bride side or groom side. They also know that specific gifts (toasters, silverware, and stemware) tend to be repeated so they want those gifts listed and have the name of the gift giver under them. The repeating gifts are only the ones that have been told you by the client (toasters, silverware, and stemware) they do not want you to determine which gifts repeat, they are just looking for those specific three. So I can implement code for only silverware, stemware, and toasters, which I have this time. But now I cannot get any correct output.

After the program has run, it should have a printout somewhat like this.

Groom side:

  1. Tom: toaster
  2. Bill: silverware
  3. Bob: stemware
  4. Steve: Lexus

Bride side:

  1. Jill: toaster
  2. Suzy: silverware
  3. Pat: stemware
  4. Karen: horse

Multiple toasters by:

Tom

Jill

Multiple silverware by:

Bill

Suzy

Multiple stemware by:

Bob

Pat

Here is what I've got so far...

var guestName;
var gift, side, kind, groomNameAccum, brideNameAccum;
var toaster, silverware, stemware, giftType;
var toasterAccum, silverwareAccum, stemwareAccum;
var noGift = 0;
var groomCounter = 0;
var brideCounter = 0;
//initalizing loop
var guest = "yes";
//start loop
while (guest == "yes") {
    side = prompt("Which side are you on? groom or bride?", "");
    guestName = prompt("Whats your name?", "");
    kind = prompt("What kind of gift?", "");

    if (side == "groom") {
        groomCounter = groomCounter + 1;
        if (groomCounter == 1) {
            groomNameAccum = "Groom     side:     <br>" + groomCounter + ". " + guestName + ": " + kind;
        } else {
            groomNameAccum = groomNameAccum + "<br>" + groomCounter + ". " + guestName + ": " + kind;
        }
    } else
    if (side == "bride") {
        brideCounter = brideCounter + 1;
        if (brideCounter == 1) {
            brideNameAccum = "<p>Bride side: <br>" + brideCounter + ". " + guestName + ": " + kind;
        } else {
            brideNameAccum = brideNameAccum + "<br>" + brideCounter + ". " + guestName + ": " + kind;
        }
    }

    if (kind == "toaster") 
        {
        toasterAccum = toasterAccum + "; " + guestName;
        }
     else if(kind == "silverware")
          {
            silverwareAccum= silverwareAccum + "; " + guestName; 
            }else if (kind == "stemware") 
            {
             stemwareAccum = stemwareAccum + "; " + guestName
            }
            else 
            {
             multiples = 0; 
             } 
    guest = prompt("Are there anymore guests?", "yes");
}


document.write(groomNameAccum);
document.write(brideNameAccum);
document.write("<p>Multiple Toasters by:<br>" + toasterAccum + "<br/>");
document.write("Multiple Silverware by:<br>" + silverwareAccum + "<br/>");
document.write("Multiple Stemware by:<br>" + stemwareAccum + "<br/>");  

As I was saying, my teacher doesn't try to teach us the shortcuts and easy stuff, because it is a classroom of technical college students. I know there are easier ways to write it out, but I don't know how yet. Hes got his formula for success that always leads me looking for correct answers....

0

There are 0 answers