I am developing an educational website that uses a Huffman Coding Tree and given user input, it prints the compressed binary on the page. I am using this code:
[CODE]
function toBinary(){
var message = document.getElementById(“word”).value;
for (rep = 0; rep < message.length; rep++)
{
write(message.substring(rep,rep+1));
}
where “word” is my textarea. I already have variables named a-z that are set correspondingly to their compressed binary strings, and my hope is that if the substring returns an “h” it will print out the binary stored in var “h”. I know that this code as it is, will only print out the letter “h”. Also, if i use:
[CODE]
write(eval(message.substring(rep,rep+1)));
it only works as I want it to 8 out of the 26 times. If anyone else knows how to fix my code so that it can stay very short like this, I would greatly appreciate it.