0

Why this code doesn't work?

I know it's uncomplete, but the function to convert a decimal into a binary number doesn't work, and it should. I'm new in web programming so many things escape from my knowledge. Thanks for answering. https://code.sololearn.com/W3556P4fRpgo/?ref=app

22nd Jun 2017, 9:21 PM
Álvaro Estévez López
Álvaro Estévez López - avatar
8 ответов
+ 3
create a new code and copy and paste this in your "javascript" tab, and then just run. you will have the same result of conversion, no need for that much of code you did. Then just apply it for your code.. i recommend looking for the toSting() and parseInt() methods on Google also so you can understand it better window.onload = function (){ //our decimal value var a = 90; //transform it into a string of base 2(binary) a = a.toString(2); alert(a); //our binary value var b = 10101110; //transform it from base 2, to base 10 b = parseInt(b,2); alert(b); }
22nd Jun 2017, 10:07 PM
Welliton Malta
Welliton Malta - avatar
+ 2
You're welcome. very useful, aren't they? i discovered their existance when making my Multiple Color Picker code in which i needed to convert from the base 10 to the base 16 and vice-versa :)
22nd Jun 2017, 10:15 PM
Welliton Malta
Welliton Malta - avatar
+ 2
you probably made aome mistake while adapting it to your code
22nd Jun 2017, 11:24 PM
Welliton Malta
Welliton Malta - avatar
+ 1
Oh, I didn't know those methods. Thanks Will.
22nd Jun 2017, 10:10 PM
Álvaro Estévez López
Álvaro Estévez López - avatar
+ 1
Yup, of course I will use it on future codes haha
22nd Jun 2017, 10:17 PM
Álvaro Estévez López
Álvaro Estévez López - avatar
0
Sorry for the mess in there haha
22nd Jun 2017, 9:21 PM
Álvaro Estévez López
Álvaro Estévez López - avatar
0
What? For some reason it isn't working. The result returns as the same number
22nd Jun 2017, 10:22 PM
Álvaro Estévez López
Álvaro Estévez López - avatar
0
I suppose it is that. I'll try to remake the code. Thanks!
23rd Jun 2017, 9:14 AM
Álvaro Estévez López
Álvaro Estévez López - avatar