Skip to content

Commit

Permalink
Added Tangent Formula Calculator and Height Unit option in BMI Calcul…
Browse files Browse the repository at this point in the history
…ator (#1850)
  • Loading branch information
isid555 authored Dec 2, 2024
1 parent 46220e9 commit e8abbc4
Show file tree
Hide file tree
Showing 11 changed files with 361 additions and 8 deletions.
11 changes: 11 additions & 0 deletions Calculators/BMI-Calculator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,20 @@ <h1>BMI Calculator</h1>
</div>
<div class="containerHW">
<div class="inputH">
<label for="heightUnit">Height Unit</label>
<select id="heightUnit" onchange="toggleHeightInput()">
<option value="cm">cm</option>
<option value="feet">feet</option>
</select>
</div>
<div class="inputH" id="heightCmInput">
<label for="height">Height(cm)</label>
<input type="number" id="height" required>
</div>
<div class="inputH" id="heightFeetInput" style="display: none;">
<label for="heightFeet">Height(feet)</label>
<input type="number" id="heightFeet" required>
</div>
<div class="inputW">
<label for="weight">Weight(kg)</label>
<input type="number" id="weight" required>
Expand Down
36 changes: 32 additions & 4 deletions Calculators/BMI-Calculator/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,50 @@ 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!';
} else if (!isPositiveNumber(height.value) || !isPositiveNumber(weight.value)) {
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) {
Expand Down Expand Up @@ -60,7 +89,6 @@ function countBmi() {

resultArea.style.display = "block";
document.querySelector(".comment").innerHTML = `You are <span id="comment">${result}</span>`;
// Update the result only after the calculation
document.querySelector("#result").innerHTML = bmi.toFixed(2);
}

Expand Down
2 changes: 1 addition & 1 deletion Calculators/BMI-Calculator/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -347,4 +347,4 @@ button.calculate:hover {
.linkDownload {
display: none;
}
}
}
6 changes: 6 additions & 0 deletions Calculators/Binary-Calculator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,21 @@ <h1>Binary Calculator</h1>
<option value="add">Addition</option>
<option value="subtract">Subtraction</option>
<option value="multiply">Multiplication</option>
<option value="division">Division</option>
<option value="leftShift">Left Shift</option>
<option value="rightShift">Right Shift</option>
<option value="and">AND Operator</option>
<option value="or">OR Operator</option>
<option value="xor">XOR Operator</option>
</select>
</div>
<button type="button" onclick="calculate()">Calculate</button>
</form>
<div id="results">
<p id="result"></p>
<p id="decimal"></p>
</div>
<div id="decimals"></div>
</div>
<script src="script.js"></script>
</body>
Expand Down
24 changes: 23 additions & 1 deletion Calculators/Binary-Calculator/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand All @@ -39,4 +60,5 @@ function calculate() {

// Display the result
document.getElementById('result').innerText = `Result: ${result}`;
document.getElementById('decimal').innerText = `Decimal Value: ${decimal}`;
}
2 changes: 1 addition & 1 deletion Calculators/Binary-Calculator/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 15 additions & 0 deletions Calculators/Tangent-Formula-Calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# <p align="center">Tangent Formula Calculator</p>

## Description :-

Calculates the tangent angle of a triangle.

## Tech Stacks :-

- HTML
- CSS
- JavaScript

## Screenshots :-

![image](https://github.com/user-attachments/assets/46cececf-442d-4bda-add4-cee006035922)
41 changes: 41 additions & 0 deletions Calculators/Tangent-Formula-Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Tangent Formula Calculator</title>
</head>

<body>
<header>
<h1>Tangent Formula Calculator</h1>
</header>

<section id="calculator">
<label for="firstSide">First Side (a):</label>
<input type="number" id="firstSide" required placeholder="Enter (a)">

<label for="secondSide">Second Side (b):</label>
<input type="number" id="secondSide" required placeholder="Enter (b)">

<label for="thirdSide">Third Side (c):</label>
<input type="number" id="thirdSide" required placeholder="Enter (c)">

<label for="calculationType">Choose Angle:</label>
<select id="calculationType">
<option value="TanA">TanA</option>
<option value="TanB">TanB</option>
<option value="TanC">TanC</option>
</select>

<button onclick="calculate()">Calculate</button>

<p id="result"></p>
</section>

<script src="script.js"></script>
</body>

</html>
60 changes: 60 additions & 0 deletions Calculators/Tangent-Formula-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
function calculate() {
// Get input values
const firstSide = parseFloat(document.getElementById('firstSide').value);
const secondSide = parseFloat(document.getElementById('secondSide').value);
const thirdSide = parseFloat(document.getElementById('thirdSide').value);
const calculationType = document.getElementById('calculationType').value;

const a = firstSide;
const b = secondSide;
const c = thirdSide;

if (isNaN(a) || isNaN(b) || isNaN(c)) {
document.getElementById("result").innerText = "Please enter valid numbers for all fields.";
return;
}

// Perform the selected calculation
let result;
if (calculationType === 'TanA') {
// Calculate the tangent of angle A
result = calculateTanA(firstSide, secondSide, thirdSide);
} else if (calculationType === 'TanB') {
// Calculate the tangent of angle B
result = calculateTanB(firstSide, secondSide, thirdSide);
} else if (calculationType === 'TanC') {
// Calculate the tangent of angle C
result = calculateTanC(firstSide, secondSide, thirdSide);
}

// Display the result
const resultElement = document.getElementById('result');
resultElement.textContent = result;
}

function calculateTanA(firstSide, secondSide, thirdSide) {
const a = firstSide;
const b = secondSide;
const c = thirdSide;
const cosA = (((b * b) + (c * c) - (a * a)) / (2 * b * c));
const sinA = Math.sqrt(1 - cosA * cosA);
return `The value of TanA is: ${sinA / cosA}`;
}

function calculateTanB(firstSide, secondSide, thirdSide) {
const a = firstSide;
const b = secondSide;
const c = thirdSide;
const cosB = (((a * a) + (c * c) - (b * b)) / (2 * a * c));
const sinB = Math.sqrt(1 - cosB * cosB);
return `The value of TanB is: ${sinB / cosB}`;
}

function calculateTanC(firstSide, secondSide, thirdSide) {
const a = firstSide;
const b = secondSide;
const c = thirdSide;
const cosC = (((a * a) + (b * b) - (c * c)) / (2 * a * b));
const sinC = Math.sqrt(1 - cosC * cosC);
return `The value of TanC is: ${sinC / cosC}`;
}
Loading

0 comments on commit e8abbc4

Please sign in to comment.