-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.js
More file actions
167 lines (137 loc) Β· 3.97 KB
/
function.js
File metadata and controls
167 lines (137 loc) Β· 3.97 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/**
* ------------------------ FUNCTIONS IN JAVASCRIPT --------------------------
*/
// ----------------------------------------------------------------------------
/**
* TEST : A normal function to print welcome note
*/
// function Welcome(user){
// console.log(`Hello ${user}!`)
// console.log("Now, You are a part of JavaScript Collection!")
// console.log("Keep Learning.")
// }
// Welcome("Ninja")
// ----------------------------------------------------------------------------
/**
* TEST : A arrow function to print welcome note
*/
// const congrats = (candidate)=>{
// console.log("Congratulations! " + candidate + " for performing excellent in the test.")
// }
// const congratulation = (candidate)=>{
// console.log(`Congratulations! ${candidate} for performing excellent in the test.`)
// }
// congrats('ninja')
// congratulation('vikash')
// ----------------------------------------------------------------------------
/**
* TEST : Calculate total marks and grade
*/
// let marksData = []
// function studentEntry(...marks){
// console.log("STUDENT REPORT")
// marksData.push(...marks)
// let [a, b, c, d, e] = marksData
// let marksToSum = [a, b, c, d, e]
// let total = marksToSum.reduce((a,b)=>a+b)
// console.log(`TOTAL MARKS : ${total}`)
// let grade = total/5
// if(grade <= 33){
// console.log(`GRADE MARKS : 'F'`)
// }
// else
// if (grade > 33 && grade <= 40) {
// console.log(`GRADE MARKS : 'C'`)
// }
// else
// if (grade > 40 && grade <= 48) {
// console.log(`GRADE MARKS : 'C+'`)
// }
// else
// if (grade > 48 && grade <= 54) {
// console.log(`GRADE MARKS : 'B'`)
// }
// else
// if (grade > 54 && grade <= 59) {
// console.log(`GRADE MARKS : 'B+'`)
// }
// else
// if (grade > 59 && grade <= 67) {
// console.log(`GRADE MARKS : 'A'`)
// }
// else
// if (grade > 67 && grade <= 84) {
// console.log(`GRADE MARKS : 'A+'`)
// }
// else
// if (grade > 85 && grade <= 89) {
// console.log(`GRADE MARKS : 'A++'`)
// }
// else
// if (grade > 89 && grade <= 100) {
// console.log(`GRADE MARKS : 'EX'`)
// }
// }
// studentEntry(83, 76, 67, 98, 69)
// studentEntry(88, 76, 66, 94, 73, 65)
// studentEntry(20, 20, 20, 20)
/**
* NOTE : If you enter more than or less than five values
* except initial five values all the other values will be neglected
*/
// ----------------------------------------------------------------------------
/**
* TEST : For getting square of one and more values
*/
// function square(...value) {
// let values = [];
// values.push(...value);
// if (values.length == 0) {
// console.log("PLEASE ENTER ATLEAST ONE VALUE TO GET RESULT!");
// } else {
// values.forEach((element) => {
// console.log(`SQUARE OF ${element} is ${element ** 2}`);
// });
// }
// }
// square(4);
// square();
// square(2, 4, 5);
/**
* NOTE : Pass values in the function to get squares, If you don't pass
* any single value in the function. A message will appear on the console.
*/
// ----------------------------------------------------------------------------
/**
* TEST : To understand implicit return in arrow function
*/
// ------> Sum of two numbers using normal function
// function add (a, b){
// return a + b
// }
// ------> Sum of two numbers using arrow function with explicit return
// let add = (a, b)=>{
// return (
// a + b
// )
// }
// ------> Sum of two numbers using arrow function with implicit return
let add = (a, b) => a + b
let sum = add(23, 23)
// console.log(sum)
/**
* TEST : To get power value from passed argument
*/
function power(num, expo){
return expo(num)
}
function square(num){
console.log(`SQUARE OF ${num} : ${num**2}`)
}
function cube(num){
console.log(`CUBE OF ${num} : ${num**3}`)
}
function quad(num){
console.log(`QUAD OF ${num} : ${num**4}`)
}
power(3, square)