javascript - Making continue statement work in a do while loop -
i need making continue statement work in do-while loop. if time of day not valid, want ignore number of cards , move next iteration of loop. right now, if not input 'morning', 'afternoon', or 'evening' 'time', loop ends.
here code:
// declare variables var time; // timestamp on batch var count; // number of cards in batch var repeat; // whether or not program repeat var m = 0; // initial number of morning cards var = 0; // initial number of afternoon cards var e = 0; // initial number of evening cards var total = 0; // initial number of cards //start loop { time = prompt("is batch's timestamp 'morning', 'afternoon' or 'evening'?"); // input value time count = prompt("how many cards in batch?"); // input value count count = parsefloat(count); // return 'count' number total = total + count; // calculate total number of cards if (time == "morning") { m = m + count; // if time 'morning', add # of cards batch # of cards 'morning' batches } else if (time == "afternoon") { = + count; // if time 'afternoon', add # of cards batch # of cards 'afternoon' batches } else if (time == "evening") { e = e + count; // if time 'evening', add # of cards batch # of cards 'evening' batches } else { continue; } repeat = prompt("do have more batches enter? enter 'y' or 'n'"); // user chooses whether end loop } while (repeat == "y"); // display results document.write("total number of cards: " + total + "<br/>"); document.write("morning cards: " + m + "<br/>"); document.write("afternoon cards: " + + "<br/>"); document.write("evening cards: " + e); ps: computer class. our activity: "in assignment pseudo-coding algorithm accumulates customer survey cards time of day. need ask input user time of day (morning, afternoon, , evening) , number of cards in batch. user needs able enter multiple batches same time of day. need use separate accumulators in loop keep track of cards loop continues iterations."
the problem while condition failing. if user enters non value input continue gets hit , code jumps down evaluate condition while (repeat == 'y')
at point repeat equals null because prompt changes never called.
since null != 'y' loop ends
Comments
Post a Comment