| JavaScript Course |
|---|
This exercise is about using brackets (parentheses) in programs. (Relevant lecture notes)
The program below is supposed to calculate the cost of a number of items after Value Added Tax has been added. To calculate the VAT on an item you must divide the vat rate (VAT) by 100 and then add it to 1, and then multiply the resulting number by the cost of the item (C).
C=promptNumber ("Enter the cost of the item")
VAT=promptNumber ("
What is the percentage VAT rate on this item?")
TC=C * 1 + VAT / 100
alert ("The cost before VAT is £" + C)
alert ( "The total cost after
VAT is £" + TC)
Question: What is the name of the variable in which the total cost is stored?
Write a program to calculate a + b divided by a - b (You can choose your own variable to put the answer in). Test the program to see if it calculates correctly. Can you think of any values of a and b that the program cannot deal with?
Make a note of the program in the above box.
End of Lesson : To go back to where you came from click on Back on the toolbar.