Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

1. ## 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>

<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.

2. 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. 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.

4. 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;
}```

5. 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.

#### Posting Permissions

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