# Assignment 5 - Computing Function Values Iteratively

You hand in this assignment by showing it to the lecturere when it is completed. It is enough to show the program after task 6 of this assignment had been done, tasks 1 to 5 are just for self-check and preparation for task 6.

1. Getting Started

2. Make yourself familiar with the program

Most of a webpage is written in Hypertext Markup Language (HTML).
But this page contains also some parts in JavaScript. Note that there is an other programming language with the name Java, but JavaScript shares with it just the name. These parts are mixed into the HTML page. In order to make it easier for you to learn to program with JavaScript, you receive almost ready programs. So you do not need to learn html.

For editing the relevant parts, you have to find the program.

• Search for the surname and givenname variables in the page: there should be a place with the var surname string in the text of the web page. Find it with the search option of your editor.
• Replace the values of the variables by your name and look at the result with a browser.
• Replace the value of the student number by your number. Use the reload button to see what you have done.
3. Analyze the function in the webpage

Which of the following equations satisfies the current function:

1. F(n) = 2n ;
2. F(n) = n2 ;
3. F(n) = 1 + 2 + … + n .
4. Start to modify the program

Read the program, in particular the loop starting with while. Edit the page and try once after the other to program the following functions:

1. F(n) = 1 × 2 × … × n ;
2. F(n) = 5n ;
3. F(n) = n3 ;
4. F(n) = 3 × n2 - 3 × n + 1 .
5. Display more values

Identify the variable which controls the number of values printed. Go to the place where it is defined. Change the value such that F(0) … F(40) are displayed.

Take the Function F(n) = 3 × n2 - 3 × n + 1 from Task 4.(d). Introduce a new function G satisfying G(n) = F(1) + F(2) + … + F(n). For doing this, declare a new variable h at the place where the other variables are declared and assign it the value 0. In the loop after computing m, let h = m + h.

Output F(n) and G(n) at each round. For the output, make an output of the form "F(n) = m, G(n) = h;" using the plus sign for string concatenation, and putting letters which do not belong to variables into quotes. So the first two lines and the last line of output should be:

F(1) = 1; G(1) = 1;
F(2) = 7; G(2) = 8;
…
F(40) = 4681; G(40) = 64000.

Take care of the dot at the end of the last line and of the semicolons before. Make sure that the loop runs until 40.

JavaScript Starts Here.
JavaScript Ends Here.