-
-
Save caesiumtea/11ca8e4829c010392ca89e8696d15715 to your computer and use it in GitHub Desktop.
codedex js course lesson 22 - two solutions
This file contains 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
// Write code below 💖 | |
let myNumber = 47; | |
let binary = ""; | |
while (myNumber > 0) { | |
if (myNumber % 2 === 0) { | |
binary = "0" + binary; | |
} else { | |
binary = "1" + binary; | |
} | |
myNumber = Math.floor(myNumber / 2); | |
} | |
// for (let i = myNumber; i > 0; i = Math.floor(i / 2)) { | |
// if (i % 2 === 0) { | |
// binary = "0" + binary; | |
// } else { | |
// binary = "1" + binary; | |
// } | |
// } | |
console.log(binary); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment