Tell us what’s happening:
I know this isn’t the most elegant code in the world but it works in VSCode. Why not in here???
Your code so far
function toDecimal(binary) {
power = 1;
sum = 0;
while (binary != "") {
sum += (binary.substring(binary.length-1) * power)
power *= 2;
binary = binary.substring(0, binary.length-1);
}
return sum;
}
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36
Challenge Information:
Daily Coding Challenge - Binary to Decimal
https://www.freecodecamp.org/learn/daily-coding-challenge/2025-10-01