+ 2

JavaScript : Decimal To Binary

Decimal <> Binary https://code.sololearn.com/WyhNLoNv9gIf/?ref=app

6th May 2018, 6:46 PM
Abderrahim Oukhrib
Abderrahim Oukhrib - avatar
1 Answer
+ 1
try this way function binaryConvert() { var num = x; if (num != Math.floor(num)) { console.log("Please enter a number"); } else if (num < 0) { console.log("Please enter a positive number"); } else { var binary = parseInt(num, 10); console.log(binary.toString(2)); } } binaryConvert();
6th May 2018, 8:04 PM
Md. Moshiur Rahman
Md. Moshiur Rahman - avatar