161 lines
3.9 KiB
JavaScript
161 lines
3.9 KiB
JavaScript
function setSize(varWidth, varHeight){
|
|
let box = document.getElementById("webBoxSel");
|
|
let boxHeight = (varHeight / 2);
|
|
let boxWidth = (varWidth / 2);
|
|
|
|
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%';
|
|
|
|
}
|
|
|
|
if(document.readyState === "loading"){
|
|
const varW = window.outerWidth;
|
|
const varH = window.outerHeight;
|
|
setSize(varW, varH);
|
|
}
|
|
|
|
window.addEventListener("resize", function (){
|
|
|
|
const varW = window.outerWidth;
|
|
const varH = window.outerHeight;
|
|
setSize(varW, varH);
|
|
});
|
|
|
|
document.getElementById("textValueBtn").addEventListener('click', function(){
|
|
let textInBox = document.getElementById("boxTextID");
|
|
let changeText = document.getElementById("textValue").value;
|
|
|
|
|
|
if(changeText.length == 0)
|
|
{
|
|
alert("Text: Not a valid text for this action.")
|
|
}else{
|
|
textInBox.innerText = changeText;
|
|
}
|
|
});
|
|
|
|
document.getElementById("textSizeBtn").addEventListener('click', function(){
|
|
let textInBox = document.getElementById("boxTextID");
|
|
let changeSize = document.getElementById("textSize").value;
|
|
|
|
if(!isNaN(changeSize))
|
|
{
|
|
alert("Size: Not a valid number for this action.")
|
|
}else{
|
|
textInBox.style.fontSize = changeSize+"px";
|
|
}
|
|
});
|
|
|
|
document.getElementById("textAngleBtn").addEventListener('click', function(){
|
|
let textInBox = document.getElementById("boxTextID");
|
|
let changeAngle = document.getElementById("textAngle").value;
|
|
|
|
if(!isNaN(changeAngle))
|
|
{
|
|
alert("Angle: Not a valid number for this action.")
|
|
}else{
|
|
textInBox.style.transform = "rotate("+changeAngle+"deg)";
|
|
}
|
|
});
|
|
|
|
|
|
document.getElementById("startBinCalc").addEventListener('click', function(){
|
|
let dezNumberToBin1 = tryParseInt(document.getElementById("binValue1").value);
|
|
let dezNumberToBin2 = tryParseInt(document.getElementById("binValue2").value);
|
|
|
|
if(isNaN(dezNumberToBin1) || isNaN(dezNumberToBin2))
|
|
{
|
|
alert("BinaryNumberAddition: At least one number is not valid for this action.")
|
|
}else{
|
|
let bin1 = calcDezToBin(dezNumberToBin1);
|
|
let bin2 = calcDezToBin(dezNumberToBin2);
|
|
|
|
additionTwoBinNumbers(bin1, bin2);
|
|
|
|
|
|
document.getElementById('binCalcResult').innerText = bin1 + " - " + bin2;
|
|
}
|
|
});
|
|
|
|
function calcDezToBin(dezNumber){
|
|
|
|
let tempNumber = dezNumber;
|
|
let remainderString = "";
|
|
|
|
let lastNumber = 0;
|
|
|
|
while(tempNumber != 0)
|
|
{
|
|
lastNumber = Math.floor(tempNumber/2);
|
|
remainderString += tempNumber%2;
|
|
tempNumber = lastNumber;
|
|
}
|
|
|
|
let binaryValue = flipBinString(remainderString);
|
|
return binaryValue;
|
|
//document.getElementById('binCalcResult').innerText = binaryValue;
|
|
}
|
|
|
|
function tryParseInt(str) {
|
|
let retValue = null;
|
|
if(str !== null) {
|
|
if(str.length > 0) {
|
|
if (!isNaN(str)) {
|
|
retValue = parseInt(str);
|
|
return retValue;
|
|
}
|
|
}
|
|
}
|
|
return str;
|
|
}
|
|
|
|
function flipBinString(remainderString)
|
|
{
|
|
let count = remainderString.length;
|
|
let remainders = [count];
|
|
|
|
for(i = 0; i < count; i++)
|
|
{
|
|
remainders[i] = remainderString[i];
|
|
}
|
|
let returnVal = remainders.reverse().join('');
|
|
return returnVal;
|
|
}
|
|
|
|
function additionTwoBinNumbers(bin1, bin2)
|
|
{
|
|
let bin1Array = bin1.split("");
|
|
let bin2Array = bin2.split("");
|
|
let tempResult = "";
|
|
|
|
if(bin1Array.length < bin2Array.length)
|
|
for(i = 0; i < bin2Array.length; i++)
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
else
|
|
for(i = 0; i < bin1Array.length; i++)
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} |