-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path14-findMax.js
More file actions
43 lines (38 loc) · 785 Bytes
/
Copy path14-findMax.js
File metadata and controls
43 lines (38 loc) · 785 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//find a max number of some positive integer number
//a simple way and interesting too
function maxNum(num1, num2, num3) {
let max = 0;
if (num1 > num2) {
if (num1 > num3) {
max = num1;
} else {
max = num3;
}
} else {
if (num2 > num3) {
max = num2;
} else {
max = num3;
}
}
return max;
}
const x = 15,
y = 9,
z = 8;
//console.log(maxNum(x, y, z));
//another solution
function max3Num(num1, num2, num3) {
let max = num1;
if (num2 > max) {
max = num2;
}
if (num3 > max) {
max = num3;
}
return max;
}
//console.log(max3Num(40, 50, 60));
//using math object
const maxNumber = Math.max(5, 34, 30);
console.log(maxNumber)