1// Create a function (you decide the name) that logs out the number 42
2// to the console
3
4// Call/invoke the function
5
6 function number(){
7 console.log(42)
8 }
9
10 number()
11//result = 42
1function runFunction() {
2 myFunction();
3}
4
5function myFunction() {
6 alert("runFunction made me run");
7}
8
9runFunction();
1function myFunc(p1, p2, pN)
2{
3 // here "this" equals "myThis"
4}
5let myThis = {};
6
7// call myFunc using myThis as context.
8// pass params to function arguments.
9myFunc.call(myThis, "param1", "param2", "paramN");
1function abc() {
2 alert('test');
3}
4
5var funcName = 'abc';
6
7window[funcName]();
1/*
2Write a function sum that takes an array of numbers and
3returns the sum of these numbers.
4Write a function mean that takes an array of numbers and
5returns the average of these numbers.
6The mean function should use the sum function.
7*/
8function sum (arr) {
9 let suma = 0;
10 for (let i = 0; i < arr.length; i++) {
11
12 let num= parseInt(arr[i]);
13 suma += num;
14 }
15 return suma;
16 }
17
18 function mean (arr) {
19 let average = sum(arr) /arr.length;
20
21 return average;
22 }