/    Sign up×
Community /Pin to ProfileBookmark

i really don’t get it… help plz!!

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!!

to post a comment
HTML

1 Comments(s)

Copy linkTweet thisAlerts:
@CharlesNov 07.2004 — [font=monospace]<script type="text/javascript">

<!--

n = 45;

alert (n.toString(2));

// -->

</script>[/font]
×

Success!

Help @Griffon03 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...