JS-Functions.

Total Number of Questions: 7
  Zero Parameter Function.

Create one function with zero parameter having a console statement.

Code:-
function log(){
    console.log("Hello World");
};

  Simple Function.

Create one function which takes two values as a parameter and print the sum of them as "Sum of 3, 4 is 7".

Code:-
function sum(a, b){
    sum = a+b;
    return `Sum of ${a} and ${b} is ${sum}`;
};

  Arrowhead Function.

Create one arrow function.

Code:-
const max = (a, b) => a > b ? a : b;
    console.log(max(5, 6));

  Print Output.

var x = 21;
var girl = function () {
  console.log(x);
  var x = 20;
};
girl ();

Output:-
Undefined

  Print Output.

var x = 21;
girl ();
console.log(x)
function girl() {
  console.log(x);
  var x = 20;
};

Output:-
Undefined
21

  Print Output.

var x = 21;
a();
b();

function a() {
  x = 20;
  console.log(x);
};

function b() {
  x = 40;
  console.log(x);
};

Output:-
20
40

  Factorial Function.

Write a function that accepts parameter n and returns factorial of n.

Code:-
function factorial(a){
    if(a !== 0){
    	let ans = 1;
    	for(let i=2; i<=a; i++){
    		ans = ans * i;
    	}
    	return ans;
    }
};
						
console.log(factorial(a));