-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions-2.js
More file actions
29 lines (21 loc) · 798 Bytes
/
Functions-2.js
File metadata and controls
29 lines (21 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// lets have a little bit deep look into our functions.
// Rest parameter
// lets create a function that hold the price of all the items in the card in an array.
function cartItemPrices(...items) {
const total = items.reduce((accValue, currValue) => accValue + currValue, 0);
return `Your bill is : ${total} /pkr`
}
console.log(cartItemPrices(200, 300, 982, 1000, 1233, 1213, 4500));
// how to take object as a function arrgument.
function userInfo(obj) {
console.log(`Hello! ${obj.username}. Welcome to Notion Community as a ${obj.desig}`);
}
userInfo({
username: "Muhammad Shakir",
desig: "Campus Leader"
})
// how to take array as a function arrgument
function getSecondNumber(getArray) {
return getArray[1];
}
console.log(getSecondNumber([200,300,303,4000]));