Week 03: Assignment – Functions

Assignment: Week 3 – Functions


Create a function that accepts two variables as arguments, compares their numerical values and writes the result on the page. Call the function 3 times with the following values:

  • 2,3
  • 3,2
  • 3,3

Tools you will need:

  • Function declaration
  • Function call
  • Conditional Statements
  • Comparison operators
  • document.write()

Example Output:

Comparing 2 and 3

result: 2 is less than 3

Comparing 3 and 2

result: 3 is greater than 2

Comparing 3 and 3

result: 3 is equal to 3

Example from Class

Extra Credit

Add an additional element to this page so that it does something else interesting.


  • What happens if you pass in 2 strings to the function?
  • What about 1 string and 1 number?
  • What if the function only receives 1 argument? Can you make a case to handle it? What about no arguments? or 3? (hint: use the ‘arguments’ array)
  • Advanced: Can you make a form so that anyone can enter any numbers they want into the function? (you will need to evaluate document.forms[0].fieldID.value) — we will go over forms later :)
  • What else can you make this function do?

Publish this page on your Assignments Page by next week’s lecture

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Web Development Courses, Rants, Tutorials and Hacks