Last active
October 14, 2022 09:02
-
-
Save johnfoderaro/f960aafdaed087a1163c to your computer and use it in GitHub Desktop.
A simple function to convert a variable value to binary.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Pretty neat 👍
Great job
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
amazing job john