SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Mar 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

    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?

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by samhor View Post
    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.
    You will want to make inquiries with your class instructor about how to use a for loop.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Mar 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No class instructor at all but thanks for the assumption. I am just practicing my js for a home project of mine.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by samhor View Post
    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.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •