forked from RBK-RebootKampTunisiaCohort3/warmUp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwarmUp5.js
52 lines (41 loc) · 1.34 KB
/
warmUp5.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
// 1) Write a function named greaterNum that:
// - takes 2 arguments, both numbers.
// - returns whichever number is the greater (higher) number.
// ex greaterNum(5, 10) => "The greater number of 5 and 10 is 10."
function greaterNum(A,B){
if (B > A) {
return B
}
return A
}
// 2) Write a function named isEven using for loop that
// - iterate from x to y.
// - return array contain the even values,
// ex: isEven(1,10) => [2,4,6,8,10]
function isEven(x, y) {
}
//3) write a function named sum that
// - Use a while loop to add up the numbers from x to y.
// ex sum(1,5) => 15
//4) Write a function named factorial that
// - Use Recursion to calculate the factorial of a number
// - the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n
// - 5! = 5*4*3*2*1 = 120
// ex : factorial(5) => 120
function factorial (n) {
if (n === 0) {
return 1;
}
return n * factorial(n - 1);
}
//5) write a function named decimals
//- the function will format a number up to specified decimal places
//- the function will return a string
//- if the parameters not a number return false
// ex :
// decimals(2100, 'a') ==> false
// decimals('a', 5) ==> false
// decimals(2.100212, 2) ==> '2.10'
// decimals(2.100212, 3) ==> '2.100'
// decimals(2100, 2) ==> '2100.00'
//