Passing Parameters to functions

It is a pain having to write separate functions for each colour, there is an easier way.

You may have been wondering what those parenthesis, (), are for at the end of the function changecolour().

We can use those to pass information to the function, that information is called a Parameter.

Create a web page with the following code on it

<head> 
<script type='text/javascript'> 
function changecolour(x)  { 
   document.body.style.backgroundColor=x;}
</script> 
</head>
<body> 
<a href="javascript:void(0);" onclick="changecolour('green');">Click me</a> 
<a href="javascript:void(0);" onclick="changecolour('wheat');">Click me</a> 
<a href="javascript:void(0);" onclick="changecolour('skyblue');">Click me</a> 
</body> 

Note that x is like a variable so we don't put it in quotes.
It will hold whatever colour we pass to the function.
We can then set the document's background colour to x.

Exercise
Add two new colours options to your page.