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.
Please refer to this page for information on how to work on your assignment.
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.
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.
reloadbutton to see what you have done.
Which of the following equations satisfies the current function:
Read the program, in particular the loop starting with while
.
Edit the page and try once after the other to program the following
functions:
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.