From 5cdadd4e497499e1c10e8a8a64fb22f1d6912d6b Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 25 Sep 2026 12:53:30 +0200 Subject: [PATCH] 25.09.2026 - 4 - BUG in binCalc? --- JavaScript/assets/js/manipulation.js | 51 ++++++++++++++-------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/JavaScript/assets/js/manipulation.js b/JavaScript/assets/js/manipulation.js index 331cc18..7f69115 100644 --- a/JavaScript/assets/js/manipulation.js +++ b/JavaScript/assets/js/manipulation.js @@ -3,21 +3,21 @@ function setSize(varWidth, varHeight){ let boxHeight = (varHeight / 2); let boxWidth = (varWidth / 2); - if((boxHeight >= 300) && (boxWidth >= 300)) - { - box.style.backgroundColor = 'red'; - }else{ - box.style.backgroundColor = 'yellow'; - } + if((boxHeight >= 300) && (boxWidth >= 300)) + { + box.style.backgroundColor = 'red'; + }else{ + box.style.backgroundColor = 'yellow'; + } box.style.width = boxWidth+'px'; box.style.height = boxHeight+'px'; let textInBox = document.getElementsByClassName('boxTextClass')[0]; - textInBox.style.color = 'blue'; - textInBox.style.margin = '25%'; - textInBox.style.marginLeft = '25%'; + textInBox.style.color = 'blue'; + textInBox.style.margin = '25%'; + textInBox.style.marginLeft = '25%'; } @@ -83,10 +83,11 @@ document.getElementById("startBinCalc").addEventListener('click', function(){ let bin1 = calcDezToBin(dezNumberToBin1); let bin2 = calcDezToBin(dezNumberToBin2); + let numbersForText = fillwithZero(bin1.split(''), bin2.split('')); let result = additionTwoBinNumbers(bin1, bin2); - //let numbersForText = fillwithZero(bin1, bin2); + - document.getElementById('binCalcResult').innerText = bin1 + " + " + bin2 + " = " + result; + document.getElementById('binCalcResult').innerHTML = "
   "+numbersForText.first.join('') + "
+ " + numbersForText.second.join('') + "
   " + result+"
"; } }); @@ -110,16 +111,16 @@ function calcDezToBin(dezNumber){ } function tryParseInt(str) { - let retValue = null; - if(str !== null) { - if(str.length > 0) { - if (!isNaN(str)) { - retValue = parseInt(str); - return retValue; - } - } - } - return str; + let retValue = null; + if(str !== null) { + if(str.length > 0) { + if (!isNaN(str)) { + retValue = parseInt(str); + return retValue; + } + } + } + return str; } function flipBinString(remainderString) @@ -138,12 +139,12 @@ function flipBinString(remainderString) function additionTwoBinNumbers(bin1, bin2) { - let binArrays = fillwithZero(bin1.split(""), bin2.split("")); - let bin1Array = binArrays.first; - let bin2Array = binArrays.second; + let binArrays = fillwithZero(bin1.split(''), bin2.split('')); + let bin1Array = binArrays.first; + let bin2Array = binArrays.second; let binOverflow = Array.from({length: bin2Array.length}, (v, k) => '0'); - let tempResult = "" + let tempResult = ""; for(i = bin1Array.length-1; i >= 0; i--){