Write a series of JavaScript functions to perform varying ta

Write a series of JavaScript functions to perform varying tasks using both function definition and function expression

Function 6 passingAverage Write a function called \"passingAverage\" using function expression notation with the following parameters & return value Parameters: This function takes an unknown number of parameters representing a list of grades (positive, whole numbers). For example, it may be called with 3 parameters (ie: passingAverage(75,42,98)), or 5 parameters (ie: passingAverage(34, 93, 77, 89, 49). Return value true if the average of all provided grades is greater than 49 and false if the average of all provided grades is less than or equal to 49. For example, if the provided parameters are 59, 42, 94 and 72, the function will return true (since the average of 59,42,94 and 72 is greater than 49). Similarly, if the provided parameters are 43, 53 and 39 the function would return false (since the average of 43, 53 and 39 is less than or equal to 49).

Solution

Here is code:

function passingAverage()
{
var args = arguments;
var sum =0;
for (var a in args) //foreach element in args calculate the sum
{
sum += args[a];
}
if (sum / args.length > 49)
return true;
else
return false;
}
console.log(passingAverage(59, 42, 10));

Output:

false

Program 2

function counter() {
var count = 1; //initail set count value
return function counts() {
return count++;
}
}
var count = counter();
console.log(count());
console.log(count());
console.log(count());

Output:

1

2

3

*All the output are visible in console panel

Write a series of JavaScript functions to perform varying tasks using both function definition and function expression Function 6 passingAverage Write a functio

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site