In this lesson are several routines, functions, that are called, executed, from the body script. They are all contained in the 'head' tag.

The first one is called with 2 parameters, arguments,...

received as 's' and 'n' ...

and writes the value of 's' to the document...

in a repetition.

Whereas the first one just does something, it writes to the document,...

the second one does something else. It makes a string...

and returns it,...

so it can be received and stored where the call is.

'for' is an alternative to 'while' , often used for handling arrays.

'i = 0' is executed once, initially, 'i < n' determines how long the repetitions continue and 'i++' is executed after each repetition.

Concise notation for : str = str + s ;

Since we know that 'repret' returns a value, we can embed it in an expression.

'calcpow' serves only a didactic purpose, because 'Math.pow' is already there to take care of such calculations.

If 'calcpow' were to be called with the value zero as second argument, it would end quickly, returning the value 1.

'return' means just that, exit the method and return to the call.

In this example it doesn't, it continues to calculate a result...

and returns that.

Calculate and return the amount including 20% VAT.

Rounded to 2 digits after the decimal point.

An often used technique is to stick the functions in a separate file and refer to it as shown( commented out ). Advantages are, that the functions can be used in several documents and can be edited separately with a convenient editor, such as the one in Eclipse's Web Tools.


Conditions between round brackets.

Relational operators :
== equal to
!= not equal to
> larger than
< less than
>= larger or equal
<= less or equal
&& logical AND, to combine conditions
|| logical OR, ditto.
! logical NOT, to reverse a condition