hey, i’m new and i’m trying to make a html program to convert a normal into a binary number that has 8 bits, and this is my script:
<html><head><title>Binary</title>
<script type = “text/javascript”>
<!– start
var num, arr;
num= window.prompt(“Enter a integer”, “34”);
arr=new Array(8);
binary();
document.write(“”+ num +” in binary number is: “);
printArray();
//—-
function binary() {
for(var i=0; i< arr.length; i++)
arr[i] = num % 2;
}
//—-
function printArray() {
for(var i=0; i< arr.length; i++)
document.writeln(“+arr[i]+”);
}
//—-
</script>
</head>
</html>
this is my script, and when i load this in my IE, i get:
34 in binary number is: +arr[i]+ +arr[i]+ +arr[i]+ +arr[i]+ +arr[i]+ +arr[i]+ +arr[i]+ +arr[i]+
the +arr[i]+ are suppose to be either 1 or 0, but all i get is this… can someone please help!!