<!DOCTYPE html>
<html lang="en-US">
<body>
<h1>JS Decimal to Octal Converter</h1>
<script>
var num = 100;
var arr = [];
var i;
var answer = [];
var value = 1;
var j = 0;
var count = -1;while(num > value)
{
count++;
value = Math.pow(8, count);
console.log(value);
arr[count] = value;
}
count = count - 1;
console.log("next");
for(i=count; i>=0; i--)
{
answer[j] = Math.floor(num / arr[i]);
j++;
console.log(num);
num = num % arr[i];
}
for(i=0; i<=count; i++)
document.write(answer[i]);
</script>
<p><strong>Note</strong>: In this example, the decimal number (100) is converted into the octal number (144).</p>
</body>
</html>