Maths and Concatenation exercise

Download this page and open with Dreamweaver. Or right click and select "View Source", then cut and paste the code to Dreamweaver.

Task 1

Add <script> tags somewhere in the source code for this page and inside them:

  1. Create a variable called vatRate and assign it the number 0.2
  2. Create a variable called mySavings and assign it the number 5461
  3. Create a variable called taxPaid and assign it the value of vatRate multiplied by mySavings

Alert

We will be using the alert() method for this task. This is a global method which spawns a pop-up window displaying any message you pass to it inside its brackets. Use it like this:

alert([text to display]);

Task 2

Add an alert statement to the end of your code to display a sentence constructed with concatenation which will read:

"On my savings of £(mySavings), I have paid £(taxPaid) VAT this tax year".

Extension

Task 1

Find out the current rate at which ISAs pay interest on savings (visit the website of a high street bank to find this). Create a javaScript to calculate the total savings after 2 years if the initial amount of money in the ISA is £3,000 and no money is withdrawn.

Calculate the amount remaining in the ISA after year 3 if, at the start of that year £1,200 is withdrawn from the account.

You will need to use at least:

In each case comment the code to explain what you are doing. Display the result using concatenation with another string in an alert().

Task 2

Your calculation works but looks a bit ugly with all those decimal places. Investigate how to round numbers in Javascript and use what you learn to round your figure to include only pounds and pence.

Task 3

Using prompt() (see the last exercise to remind yourself how to do this), gather figures from the user for interest rate and the amount of savings they have at present. Use these figures to calculate the accumulated savings and interest over a three year period.

Remember, when you recieve input from prompt() it will be a String variable. In order to perform maths operations with this you will need to convert it to a Number variable.