JS function with a return statement
by danielkwood
HTML
<html>
<head>
<title>Functions</title>
<script src="script.js"></script>
</head>
<body>
</body>
</html>
JavaScript
// This function has three parameters
function average(num1, num2, num3){
var result = (num1 + num2 + num3) / 3;
// The function returns a value
return result;
}
// The returned value from the function can then be used
// eg. it can be stored in a variable...
var myAverage = average(10, 15, 12);
// ...or displayed or used in another operation
console.log(myAverage);