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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    coffee shop calculator.

    going crazy now.
    been trying to work on this problem.
    this is the basis of this

    espresso costs 1.40 served as shot
    latte/cappuccino cost the same 8 ouce 1.95 12 ounce 2.35 16 ounce 2.75
    american costs 1.20 for first 8 ounces .30 cents for each additional 8 ounce (0.0375 per ounce)

    final price needs to be taxed 0.055.

    (have not got that far)

    Code:
    <html>
    
    <head><title>Coffee Shop Calculator </title></head>
    
    <script type = "text/javascript">
    
    var drinkType 
    
    var price;
    
    var espressoPrice;
    var lattePrice;
    var cappuccinoPrice;
    var americanoPrice;
    var shotSize
    var americanoPrice1
    var coffeeSize
    
    
    drinkType = drinkType = prompt( " Please enter in the type of drink you would like " );
    if(drinkType!='espresso')
    coffeeSize = coffeeSize = prompt( " please enter how many ounces you want " )
    else if(drinkType=='espresso')
    shotSize = shotSize = prompt( " Please enter how many shots extra you would like in your espressso ");
    
    if(shotSize > '1')
     espressoPrice =  (0.50 * shotSize) - 0.50;
    
    if coffeeSize == '8'
    	lattePrice = 1.95 
    	cappuccinoPrice = 1.95 
    	americanoPrice = 1.20
    
    
    if(coffeeSize == '12')
    	lattePrice = 2.35
    	cappuccinoPrice = 2.35
    if(coffeeSize == '16')
    	lattePrice = 2.75
    	cappuccinoPrice = 2.75
    
    if(drinkType == 'Latte')
    	price = lattePrice * 0.055
    
    if(drinkType == 'Cappuccino')
    	price = cappuccinoPrice * 0.055
    
    </script>
    
    <body>
    
    </body>
    
    </html>
    the espresso cost is the only one that would work. the rest not.
    i am just in the basics of javescript beginner course, so keep it to the basics of basics.
    Last edited by VIPStephan; 05-07-2012 at 09:56 AM. Reason: added code BB tags

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,981
    Thanks
    56
    Thanked 557 Times in 554 Posts
    the first thing you need to do is to be able to look at your code in a debugger. I like the one in Chrome (spanner>tools>javascript console).

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Hint -

    if coffeeSize == '8'
    lattePrice = 1.95
    cappuccinoPrice = 1.95
    americanoPrice = 1.20


    Where are your brackets and braces?

    BTW, when posting here please help us to help you by following the posting guidelines and wrapping your code in CODE tags. This means use the octothorpe or # button on the toolbar. You can (and should) edit your previous post.


    Quizmaster: What is the Latin name of the province in Canada which means "New Scotland" in English?
    Contestant: Johannesburg.

    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.

  • #4
    New Coder
    Join Date
    Oct 2010
    Posts
    56
    Thanks
    2
    Thanked 0 Times in 0 Posts
    To reiterate what Philip said, js functions are writen like this:

    Code:
    function functionName()
    {
    code to be executed;
    }
    You're missing brackets, it's going to give you all sorts of errors without them, and not recognize that it's a function at all. 'IF' statements work the same way. Like this:

    Code:
    if (x!=1)
    {
    code to be executed;
    }
    Last edited by Prime8; 05-07-2012 at 02:50 PM.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Prime 8 is entirely correct, but it is recommended that the opening brace { is placed on the same line as the function, if, else, do, while, or for statement and not on the following line. This is because of something known as automatic semi-colon insertion. If you disregard this advice it is looking out and one day it will rise up and bite you in the undercarriage, and create an error which can be hard to find.

    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.


  •  

    Posting Permissions

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