COMP249 Web Technology
Practical - Week 4
The aim of this practical is to give you some experience with basic JavaScript.
JavaScript
The main thing you should do this week with respect to JavaScript is ensure that you can write and test some simple scripts via your browser. Here are some simple problems you can work on. To do this you'll need to familiarise yourself with the alert, prompt and document.write functions which are covered in the book and in my notes.
- Output the first 20 Fibonacci numbers, which are defined as in the sequence (1, 1, 2, 3, ...) where each number is the sum of the previous two numbers in the sequence. Use document.write() to insert your result into the HTML page. Experiment with putting the SCRIPT tag in various places in the document.
- Input: a text string using prompt. Output: either Illegal Name or Legal Name via alert. A name is legal if it begins with the letter 'S' or 'C' and has an even number of letters.
- Use JavaScript to generate a six times table, that is an
HTML table of the numbers 1 to 12 multiplied by six. Eg:
1 6 6 2 6 12 3 6 18 etc... Use document.write to insert the HTML code for the table into the document
- Write a simple investment calculator. Your page should include a form with entries for amount, interest rate, period and total and a submit button. When the submit button is pressed, a javascript procedure should run to calculate the value of total from the other fields. To calculate the total, assume that interest is paid yearly. Write a for loop over the number of years multiplying the amount by the interest rate each time. Note that there are lots of examples of this kind of calculator out on the net, try to do this yourself without peeking!
Portfolio
Try to improve on and add to the work you have put on the Portfolio Server. Take one of the examples above and use it as a starting point for the second piece of work in your portfolio. Think about what you would like to be able to do and write that in the comment on your item. For the first checkpoint (March 25th) we will be giving feedback as much on what you are intending to do as what you have done. Use your imagination!