DEV Community

Siddharth Kanojiya
Siddharth Kanojiya

Posted on • Edited on

Functions in JavaScript | JavaScript #9

// Function in JavaScript
// A JavaScript function is a block of code designed to perform a particular tast

function onePlusAvg(x,y){
console.log("Done")
return 1 + (x+y)/2
}

// function onePlusAvg(x,y){
// console.log("Done")
// return Math.round(1 + (x+y)/2)
// }

let a = 1;
let b = 2;
let c = 3;

// console.log("Average of a and b is ", (a + b)/2)
// console.log("Average of b and c is ", (a + b)/2)
// console.log("Average of a and c is ", (a + b)/2)

// console.log("One plus Average of a and b is ", onePlusAvg(a,b))
// console.log("One plus Average of a and b is ", onePlusAvg(b,c))
// console.log("One plus Average of a and b is ", onePlusAvg(a,c))

console.log("One plus Average of a and b is ", onePlusAvg(a,b))
console.log("One plus Average of a and b is ", onePlusAvg(b,c))
console.log("One plus Average of a and b is ", onePlusAvg(a,c))

Top comments (1)

Collapse
 
goku_91 profile image
Si

very Nice