Assignment 2 - Easy Functions.

You hand in this assignment by showing it to the lecturer when it is completed.

  1. Getting Started

    Please refer to this page for information on how to work on your assignment.

  2. Outline

    This assignment is dedicated to train to write very short routines in form of functions. Here is an example:

    function factorial(x)
    {
        var y = 1;
        var z = 1;
        while(z < x)
        {
            z = z + 1;
            y = y * z;
        }
        return y;
    }
    

    This function computes the factorial. One can also write it as a recursive function which calls itself. In this case, it is necessary to make sure that the call of the function to itself uses smaller values than the original call:

    function factorial(x)
    {
        if(x < 2)
        {
            return 1;
        }
        return x * factorial(x - 1);
    }
    
  3. Task of this exercise

    The task is now to write functions on your own. They can be found in the source code.

JavaScript Starts Here.
JavaScript Ends Here.