function convertToBinary(x) {
let bin = 0;
let rem, i = 1;
/*rem is the remaining Number, i is the current step total, bin is the binary answer*/
while (x != 0) {
rem = x % 2;
x = parseInt(x / 2);
bin = bin + rem * i;
i = i * 10;
}
return bin;
}
console.log(convertToBinary(4))