diff --git a/Maths/decimal-to-octal.js b/Maths/decimal-to-octal.js new file mode 100644 index 0000000..6c1bbd1 --- /dev/null +++ b/Maths/decimal-to-octal.js @@ -0,0 +1,15 @@ +function convertToOctal(num) { + if (typeof num !== "number") { + throw new Error("Input must be a valid number."); + } + + if (num <= 0 || num >= 1e9) { + throw new Error( + "Number must be greater than zero and less than one billion." + ); + } + + return num.toString(8); +} + +console.log(convertToOctal(63)); // 77