Assignment
let arr = [1, 3, 5, 7, 8, 9];
let arrayAverage = (arr) => {
let sum = 0;
for (let i = 0; i < arr.length; i++) {
sum += arr[i];
}
let avg = sum / arr.length;
return avg;
};
console.log(arrayAverage(arr));
// Q2-an arrow function that takes a number and returns if it is even number or not
const Even = (n) => n % 2 == 0;
console.log(Even(8));
// Q3
const obj = {
message: "hello world",
logMessage() {
console.log(this.message);
},
};
setTimeout(obj.logMessage, 1000);
// Q4
let length = 4;
function callback() {
console.log(this.length);
}
const object = {
length: 5,
method(callback) {
callback();
},
};
object.method(callback);

Comments
Post a Comment