As a newcomer to coding and Javascript, I have been given an assignment that requires me to convert base 10 numbers to binary without using specific built-in methods in Javascript (such as alert(a.toString(16))). The constraints are that I can only use loops, arrays, and functions. Here is what I have so far:
var number = prompt("Enter an unsigned base 10 number");
if (number>=0) {
var base = prompt("Enter b for binary, o for octal, or h for hexadecimal");
if (base=="h"||base=="H") {
;
}
It's clear that I don't have much to work with at the moment. I am wondering about the equation or formula I should use to perform the conversion from base 10 to binary. Also, I'm unsure of how to handle representing A=10, B=11, C=12, and so on for a hexadecimal base. Any guidance you can provide would be greatly appreciated!