From 2a1cfa1cd4606ce112eebbee1dd1559830f4ff0a Mon Sep 17 00:00:00 2001 From: isid555 Date: Wed, 14 Aug 2024 20:39:57 +0530 Subject: [PATCH 1/2] Issue Title: Enhance `convertFeetToCm` Function to Include Centimeters Conversion --- Calculators/BMI-Calculator/index.html | 11 ++++++++ Calculators/BMI-Calculator/script.js | 36 ++++++++++++++++++++++++--- Calculators/BMI-Calculator/style.css | 4 ++- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/Calculators/BMI-Calculator/index.html b/Calculators/BMI-Calculator/index.html index 3d69ac749..a382e7123 100644 --- a/Calculators/BMI-Calculator/index.html +++ b/Calculators/BMI-Calculator/index.html @@ -33,9 +33,20 @@

BMI Calculator

+ + +
+
+
diff --git a/Calculators/BMI-Calculator/script.js b/Calculators/BMI-Calculator/script.js index b638f58af..da44d7e17 100644 --- a/Calculators/BMI-Calculator/script.js +++ b/Calculators/BMI-Calculator/script.js @@ -15,6 +15,17 @@ var span = document.getElementsByClassName("close")[0]; // document.querySelector("#result").innerHTML = "00.00"; function calculate() { + + var heightUnit = document.getElementById("heightUnit").value; + var heightValue; + + if (heightUnit === "cm") { + heightValue = document.getElementById("height").value; + } else { + var heightFeet = document.getElementById("heightFeet").value; + heightValue = convertFeetToCm(heightFeet); + } + if (age.value == '' || height.value == '' || weight.value == '' || (male.checked == false && female.checked == false)) { modal.style.display = "block"; modalText.innerHTML = 'ALL fields are required!'; @@ -22,14 +33,32 @@ function calculate() { modal.style.display = "block"; modalText.innerHTML = 'Please enter valid positive values for height and weight!'; } else { - countBmi(); + countBmi(heightValue); } } function isPositiveNumber(value) { return /^\d*\.?\d+$/.test(value) && parseFloat(value) > 0; } -function countBmi() { - var p = [age.value, height.value, weight.value]; +function convertFeetToCm(feet) { + return (feet * 30.48) ; +} +function toggleHeightInput() { + var heightUnit = document.getElementById("heightUnit").value; + var heightLabel = document.querySelector("label[for='height']"); + + if (heightUnit === "cm") { + document.getElementById("heightCmInput").style.display = "block"; + document.getElementById("heightFeetInput").style.display = "none"; + heightLabel.textContent = "Height(cm)"; + } else { + document.getElementById("heightCmInput").style.display = "none"; + document.getElementById("heightFeetInput").style.display = "block"; + heightLabel.textContent = "Height(feet)"; + + } +} +function countBmi(heightValue) { + var p = [age.value, heightValue, weight.value]; if (male.checked) { p.push("male"); } else if (female.checked) { @@ -60,7 +89,6 @@ function countBmi() { resultArea.style.display = "block"; document.querySelector(".comment").innerHTML = `You are ${result}`; - // Update the result only after the calculation document.querySelector("#result").innerHTML = bmi.toFixed(2); } diff --git a/Calculators/BMI-Calculator/style.css b/Calculators/BMI-Calculator/style.css index e1618ed15..1633babf4 100644 --- a/Calculators/BMI-Calculator/style.css +++ b/Calculators/BMI-Calculator/style.css @@ -347,4 +347,6 @@ button.calculate:hover { .linkDownload { display: none; } -} \ No newline at end of file +} + + From 0c605a9b8edce5be493e0544104970572f563342 Mon Sep 17 00:00:00 2001 From: isid555 Date: Thu, 15 Aug 2024 01:15:13 +0530 Subject: [PATCH 2/2] Feature Enhancement: Added Decimal Output, Division Method, OR,AND ,XOR Operators for Binary Inputs --- Calculators/Binary-Calculator/index.html | 8 ++++++++ Calculators/Binary-Calculator/script.js | 24 +++++++++++++++++++++++- Calculators/Binary-Calculator/style.css | 3 ++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Calculators/Binary-Calculator/index.html b/Calculators/Binary-Calculator/index.html index 19256dbb5..9c0eb9681 100644 --- a/Calculators/Binary-Calculator/index.html +++ b/Calculators/Binary-Calculator/index.html @@ -26,14 +26,22 @@

Binary Calculator

+ + + +

+

+
+
+
diff --git a/Calculators/Binary-Calculator/script.js b/Calculators/Binary-Calculator/script.js index 33dc5d26c..bc8b36e0d 100644 --- a/Calculators/Binary-Calculator/script.js +++ b/Calculators/Binary-Calculator/script.js @@ -14,23 +14,44 @@ function calculate() { const num1 = parseInt(binary1, 2); const num2 = parseInt(binary2, 2); let result; - + let decimal; // Perform the selected operation switch (operation) { case "add": result = (num1 + num2).toString(2); + decimal = (num1 + num2); break; case "subtract": result = (num1 - num2).toString(2); + decimal = (num1 - num2); break; case "multiply": result = (num1 * num2).toString(2); + decimal = (num1 * num2); break; case "leftShift": result = (num1 << num2).toString(2); + decimal = (num1 << num2); break; case "rightShift": result = (num1 >> num2).toString(2); + decimal = (num1 >> num2); + break; + case "division": + result = (num1 / num2).toString(2); + decimal = (num1 / num2); + break; + case "and": + result = (num1 && num2).toString(2); + decimal = (num1 && num2); + break; + case "or": + result = (num1 || num2).toString(2); + decimal = (num1 || num2); + break; + case "xor": + result = (num1 ^ num2).toString(2); + decimal = (num1 ^ num2); break; default: alert("Invalid operation."); @@ -39,4 +60,5 @@ function calculate() { // Display the result document.getElementById('result').innerText = `Result: ${result}`; + document.getElementById('decimal').innerText = `Decimal Value: ${decimal}`; } diff --git a/Calculators/Binary-Calculator/style.css b/Calculators/Binary-Calculator/style.css index 4367e7621..b074c5199 100644 --- a/Calculators/Binary-Calculator/style.css +++ b/Calculators/Binary-Calculator/style.css @@ -15,7 +15,7 @@ body { box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); transition: transform 0.3s; width: 500px; - height: 400px; + height: 450px; } .container:hover { @@ -79,6 +79,7 @@ button:hover { } #results { + margin-top: 20px; text-align: center; }