Skip to content

Instantly share code, notes, and snippets.

@caesiumtea
Created November 11, 2023 07:07
Show Gist options
  • Save caesiumtea/11ca8e4829c010392ca89e8696d15715 to your computer and use it in GitHub Desktop.
Save caesiumtea/11ca8e4829c010392ca89e8696d15715 to your computer and use it in GitHub Desktop.
codedex js course lesson 22 - two solutions
// 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