-
Notifications
You must be signed in to change notification settings - Fork 77
/
05_functions.js
66 lines (53 loc) · 1.22 KB
/
05_functions.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
// Function Declaration - greet someone
function greet(name) {
return "Hello, " + name;
}
// Function Call
let ans1 = greet("Bharat");
let ans2 = greet("Harkirat");
let ans3 = greet("Deepak");
// log the output
console.log(ans1); // Hello, Bharat
console.log(ans2); // Hello, Harkirat
console.log(ans3); // Hello, Deepak
// Function Declaration - sum of two numbers
function sum(a, b) {
let totalSum = a + b;
return totalSum;
}
// Function Call
let sum1 = sum(2, 3);
let sum2 = sum(5, 10);
// log the output
console.log(sum1); // 5
console.log(sum2); // 15
// Function Declaration - can vote or not
function canVote(age) {
if (age >= 18) {
return true;
} else {
return false;
}
}
// Function Call
let ans4 = canVote(20);
let ans5 = canVote(15);
// log the output
console.log(ans4); // true
console.log(ans5); // false
// Function Declaration - can vote or not
function canVote1(age) {
// if (age >= 18) {
// console.log("Yes, you can vote");
// } else {
// console.log("No, you can't vote");
// }
if (age >= 18) {
console.log("Yes, you can vote");
}
if (age < 18) {
console.log("No, you can't vote");
}
}
canVote1(20); // Yes, you can vote
canVote1(15); // No, you can't vote