Skip to content

Commit 72029f0

Browse files
committed
fix: clear 'binary' before reuse and add console logs
- Clear 'binary' before using it again. - Add console logs to visualize the results better.
1 parent e8e4ec9 commit 72029f0

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

4-loops/22-based-numbers.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@ for (let i = myNumber; i >= 1 ; i = Math.floor(i/2)) {
1212
binary = "1" + binary;
1313
}
1414
}
15+
console.log('With for loop: ' + binary);
1516

1617
// With while loop
1718
let i = myNumber;
19+
binary = "";
1820
while (i >= 1) {
1921
if (i % 2 == 0) {
2022
binary = "0" + binary;
2123
} else {
2224
binary = "1" + binary;
2325
}
24-
26+
2527
i = Math.floor(i/2);
2628
}
29+
30+
console.log('With while loop: ' + binary);

0 commit comments

Comments
 (0)