Is a loop needed? I have NO idea!

Hello All,

I have made the below code but i want to add something extra to it. I have tried to do it several times already but the code just seems to stop working :frowning:

What i need it to do is to keep asking the user to enter the CD Title and CD Cost repeatedly and to total all the CD Costs together.

<html>
<body>
<script language=‘JavaScript’> //set the language
a=(prompt(‘please enter the CD Title:’,0)); // enter the cd title promt
b=parseFloat(prompt(‘please enter the CD Cost:’,0)); // enter the cd cost promt

document.writeln(’ your CD Title is: <b>’ + a + ‘</b>’); //write the cd title to the screen in bold
document.writeln(’ your CD Cost is: <b>’ + b + ‘</b>’); //write the cd cost to the screen

</script>
</body>
</html>

E.g.

Customer wants to buy X CD’s.

The prompt will appear X times untill the customer has no more CD’s they want to buy

All the CD Titles & CD Costs should be written to the screen

With Total

End Product:

your CD Title is: RnB Classic Vol 1 your CD Cost is: 1.00
your CD Title is: RnB Classic Vol 2 your CD Cost is: 1.00
your CD Title is: RnB Classic Vol 3 your CD Cost is: 1.00

Total Cost 3.00

Can anyone help?

You will want to make inquiries with your class instructor about how to use a for loop.

No class instructor at all but thanks for the assumption. I am just practicing my js for a home project of mine.

In that case, we have A book here called Simply JavaScript that an help you to learn.

Also, We have a section of links and resources that contains beginner articles, and other resources that you can use to further your education.