You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. Write a javascript function named is_integer which checks if the passed argument is an integer. You can use any mathematical operator or functions defined in the Math object.
3
+
2. Using the forEach function defined for an array, find the sum of the array of numbers. [function add_all(arr) {...}]
4
+
3. Write a JavaScript program to convert temperatures to and from celsius, fahrenheit. [ Use the formula : c/5 = (f-32)/9, where c = temperature in celsius and f = temperature in fahrenheit]
5
+
4. Write a factorial function that returns the factorial of a given number, n. Make sure you return the calculated value and not just print it. [function factorial(n){...}]
6
+
5. Write a javascript function that converts a given amount of money into coins of denominations (1, 2, 5, 10 and 25). [function convert_to_coins(amount) {...}]. You may choose to print the coin denominations used on the console. E.g. convert_to_coins(87) should print 25 25 25 10 2.
7
+
8
+
*This project/author of this project is not endorsed, connected, or related to Udemy or its products and courses in any way. The solutions provided are just for reference and exercises.*
9
+
10
+
[Click Here](External_Courses\Udemy\Course\README.md) for more details
1. Write a javascript function named is_integer which checks if the passed argument is an integer. You can use any mathematical operator or functions defined in the Math object.
5
+
*/
6
+
7
+
functionis_integer(num){
8
+
if(num%1===0){
9
+
returntrue;
10
+
}else{
11
+
returnfalse;
12
+
}
13
+
}
14
+
constmyNum=11
15
+
// const myNum = 11.05
16
+
console.log(myNum)
17
+
console.log(is_integer(myNum))
18
+
19
+
/*
20
+
2. Using the forEach function defined for an array, find the sum of the array of numbers. [function add_all(arr) {...}]
21
+
*/
22
+
23
+
constMyArr=[1,2,3,4]
24
+
25
+
functionadd_all(arr){
26
+
letsum=0;
27
+
arr.forEach(function(num){
28
+
sum+=num;
29
+
});
30
+
returnsum;
31
+
}
32
+
33
+
console.log(add_all(MyArr))
34
+
/*
35
+
3. Write a JavaScript program to convert temperatures to and from celsius, fahrenheit. [ Use the formula : c/5 = (f-32)/9, where c = temperature in celsius and f = temperature in fahrenheit]
36
+
*/
37
+
38
+
functionconvert(temperature,type){
39
+
// 0 --> to celsius
40
+
// 1 --> to fahrenheit
41
+
if(type=0){
42
+
return(temperature-32)*5/9;
43
+
}
44
+
elseif(type=1){
45
+
return(temperature*9/5)+32;
46
+
}
47
+
}
48
+
49
+
consttemperature=23
50
+
console.log(temperature)
51
+
console.log(convert(temperature,1))
52
+
53
+
/*
54
+
4. Write a factorial function that returns the factorial of a given number, n. Make sure you return the calculated value and not just print it. [function factorial(n){...}]
55
+
*/
56
+
57
+
functionfactorial(n){
58
+
if(n===0){
59
+
return1
60
+
}
61
+
else{
62
+
returnn*factorial(n-1)
63
+
}
64
+
65
+
}
66
+
67
+
console.log(factorial(3))
68
+
69
+
/*
70
+
5. Write a javascript function that converts a given amount of money into coins of denominations (1, 2, 5, 10 and 25). [function convert_to_coins(amount) {...}]. You may choose to print the coin denominations used on the console. E.g. convert_to_coins(87) should print 25 25 25 10 2.
*This project/author of this project is not endorsed, connected, or related to Udemy or its products and courses in any way. The solutions provided are just for reference and exercises.*
0 commit comments