Skip to content

Commit a9d88ea

Browse files
Merge pull request akshitagit#77 from iyosayi/decimal-to-octal
Created decimal to octal converter function
2 parents 6a2081d + b8c6b96 commit a9d88ea

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Maths/decimal-to-octal.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function convertToOctal(num) {
2+
if (typeof num !== "number") {
3+
throw new Error("Input must be a valid number.");
4+
}
5+
6+
if (num <= 0 || num >= 1e9) {
7+
throw new Error(
8+
"Number must be greater than zero and less than one billion."
9+
);
10+
}
11+
12+
return num.toString(8);
13+
}
14+
15+
console.log(convertToOctal(63)); // 77

0 commit comments

Comments
 (0)