-
Notifications
You must be signed in to change notification settings - Fork 3
/
function.js
80 lines (60 loc) · 1.44 KB
/
function.js
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
Function
# What Is Function ?
# User-Defined vs Built In
# Syntax + Basic Usage
# Example From Real Life
# Parameter + Argument
# Practical Example
*/
function sayWelcome(userName) {
console.log(`Welcome ${userName}`);
}
sayWelcome('ashraf')
sayWelcome('shenoo')
// ==========================================================
function sayHello(userName, age) {
if (age < 18) {
console.log(`App is Not Avalibale For You`);
} else {
console.log(`Hello ${userName} Your Age is ${age}`);
}
}
sayHello('Ashraf', 21)
sayHello('Ali', 17)
// ==========================================================
function generateYears(start, end, notPrint) {
for (let i = start; i <= end; i++) {
if (i === notPrint) {
continue;
}
console.log(i);
}
}
generateYears(1982, 2000, 1999);
// arrrow functions
const arrow = (name) => {
console.log(`hello ${name}`);
}
arrow('ahraf')
const sum = (n1, n2) => {
console.log('#'.repeat(20));
console.log(n1 + n2);
}
sum(10, 2)
const returnFun = (numOne, numTwo) => numOne - numTwo;
console.log(returnFun(10, 2));
// start fumction with return
function sumExampleTwo(nOne , nTwo) {
return nOne + nTwo
}
console.log(sumExampleTwo(100, 50));
function generate(start, end) {
for (let i = start; i <= end; i++) {
if (i === 15) {
return `Interrupting`;
}
console.log(i);
}
}
generate(10, 20);