- Explain the purpose and function of a Function
- Write Functions
- Write Functions with 0, 1, and 2+ parameters
- Invoke Functions as Expressions
Turn to your neighbor and explain why functions are useful. Be prepared to share your answer with the class.
On your desks, write a function that prints out the numbers 0 - 9.
On your desks, write a function named printIfDivisible that takes two parameters:
- Name first parameters
countUpTo. - Name second parameter
divisor.
Your function should loop from 0 to and include countUpTo, and only prints out numbers in the count if they are evenly divisible by divisor
Example:
printIfDivisible(10,2) // 0, 2, 4, 6, 8, 10
printIfDivisible(10,3) // 0, 3, 6, 9
printIfDivisible(20,5) // 0, 5, 10, 15, 20
On your desks, write a function named sumAll that will take 0 or more arguments, and return the sum of all arguments.
Example:
sumAll() // 0
sumAll(10) // 10
sumAll(1,2,3,4,5,6) // 21
The following equation is an equation that gets the length of a hypotenuse of a right angle, where a and b and the lenghts of the sides at a right angle.
c = sqrt(a^2 + b^2)
Using the following functions:
- Math.pow()
- Math.sqrt()
And the following variables:
var a = 3;
var b = 4;
Write an expression that creates a variable named c and assign the value of the length of the hypotenuse of a right angle with sides if length a and b