Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Javascript - discount calculations

    You have a product that is on sale. Each day of the sale, the price drops 10% from its previous price. The sale lasts for 4 days. I have to write a program that processes this problem using a loop. Each pass through the loop should generate the sale price for a a day of the sale and display that price along with the day number.

    Which loop would I use ? I cannot seem to figure this out.

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,145
    Thanks
    38
    Thanked 505 Times in 499 Posts

    Lightbulb

    If you know the limits of the loop, why not just use them.
    Code:
    for (var day = 1; day <= 4; day++) {
    // discount calculations and display
    
    }

  • Users who have thanked jmrker for this post:

    JavaLearner22 (03-20-2013)

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,298
    Thanks
    203
    Thanked 2,561 Times in 2,539 Posts
    @JavaLearner22

    You should be aware that Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Rather like Austria and Australia!

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Tags for this Thread

    Posting Permissions

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