1

I'm trying to make a program where the user can enter how many CD's they wish to enter and then print out what they have entered onto a screen.

Is there a way to enable multiple entries from one prompt box?

<script language="JavaScript">
var titleCD = [];
var costCD = [];
var subTotal = [];
var entries = parseInt(prompt("How many CDs do you wish to enter?",0)); 
while(entries>0) {
   titleCD = prompt("What is the title of your CD?");
   costCD = parseInt(prompt("What is the cost of that CD?", 0));
   entries--;
}
b = new String(titleCD + ": " + "£" + costCD + "<br>");
document.write(b.bold());
u = new String("The subtotal cost of all CDs is: £" + subTotal);
document.write(u.toUpperCase());
</script>
Andrew Lohr
  • 5,380
  • 1
  • 26
  • 38
Brandon Brock
  • 52
  • 2
  • 6
  • 2
    Perhaps you should use a html form rather than js prompts? – Pete Mar 06 '18 at 16:09
  • There isn't that I know of, you could use 2 in a row though. – Feathercrown Mar 06 '18 at 16:10
  • I would for sure suggest you use a html form as said above, but if you NEED to do it through the prompt you can ask your user to enter data in a specific format (maybe comma separated) and you can parse it using split and comma as the delimiter. – Andrew Lohr Mar 06 '18 at 16:51

0 Answers0