Skip to content

Commit c7f0f83

Browse files
feat: add math functions
1 parent 4a83d4f commit c7f0f83

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Topic1/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,19 @@ console.log(num12);
100100

101101
// let num13 = 11++; // you cannot use this way directly on constant
102102
// console.log(num13);
103+
104+
105+
// Question: Math Functions
106+
console.log(Math.round(10.5));
107+
console.log(Math.ceil(10.1));
108+
console.log(Math.floor(10.9));
109+
console.log(Math.trunc(18.98)); // removes the decimal part
110+
console.log(Math.pow(2, 5)); // 2^5
111+
console.log(Math.sqrt(25));
112+
console.log(Math.cbrt(8));
113+
console.log(Math.abs(-15)); // absolute (converts negative value to positive)
114+
console.log(Math.max(78, 65, 12, 43)); // returns max value
115+
console.log(Math.min(12, 2, 34, 1)); // returns min value
116+
console.log(Math.trunc((Math.random() * 9000) + 1000)); // retuns between 0 to 1 if don't pass anything
117+
let num13 = 89.3243243;
118+
console.log(typeof num13.toFixed(2)); // 2 numbers after decimal but toFixed also covert number into string type

0 commit comments

Comments
 (0)