forked from Rakesh9100/CalcDiverse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more units in Weight Calculator (Rakesh9100#1086)
- Loading branch information
1 parent
8b9fd4b
commit 69fbd1f
Showing
5 changed files
with
83 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,59 @@ | ||
function updateInputs() { | ||
var conversionType = document.getElementById('conversionType').value; | ||
var kgInput = document.getElementById('kgInput'); | ||
var lbInput = document.getElementById('lbInput'); | ||
const conversionType = document.getElementById('conversionType').value; | ||
|
||
// Disable both inputs and clear their values | ||
kgInput.disabled = true; | ||
kgInput.value = ""; | ||
lbInput.disabled = true; | ||
lbInput.value = ""; | ||
// Disable all inputs | ||
document.getElementById('kgInput').disabled = true; | ||
document.getElementById('lbInput').disabled = true; | ||
document.getElementById('gInput').disabled = true; | ||
document.getElementById('ozInput').disabled = true; | ||
|
||
// Enable the input relevant to the selected conversion type | ||
if (conversionType === 'kgToLb') { | ||
kgInput.disabled = false; | ||
} else if (conversionType === 'lbToKg') { | ||
lbInput.disabled = false; | ||
// Enable the relevant input based on the selected conversion | ||
if (conversionType === 'kgToLb' || conversionType === 'kgToG' || conversionType === 'kgToOz') { | ||
document.getElementById('kgInput').disabled = false; | ||
} else if (conversionType === 'lbToKg' || conversionType === 'lbToOz' || conversionType === 'lbToG') { | ||
document.getElementById('lbInput').disabled = false; | ||
} else if (conversionType === 'gToOz' || conversionType === 'gToLb') { | ||
document.getElementById('gInput').disabled = false; | ||
} else if (conversionType === 'ozToG' || conversionType === 'ozToKg') { | ||
document.getElementById('ozInput').disabled = false; | ||
} | ||
} | ||
|
||
function convert() { | ||
var conversionType = document.getElementById('conversionType').value; | ||
var kgInput = document.getElementById('kgInput'); | ||
var lbInput = document.getElementById('lbInput'); | ||
const conversionType = document.getElementById('conversionType').value; | ||
let result; | ||
|
||
if (conversionType === 'kgToLb' && kgInput.value !== "") { | ||
var kgToLb = kgInput.value * 2.20462; | ||
document.getElementById('result').innerHTML = kgInput.value + " kilograms is equal to " + kgToLb.toFixed(2) + " pounds."; | ||
} else if (conversionType === 'lbToKg' && lbInput.value !== "") { | ||
var lbToKg = lbInput.value / 2.20462; | ||
document.getElementById('result').innerHTML = lbInput.value + " pounds is equal to " + lbToKg.toFixed(2) + " kilograms."; | ||
} else { | ||
document.getElementById('result').innerHTML = "Please enter a value."; | ||
if (conversionType === 'kgToLb') { | ||
const kg = parseFloat(document.getElementById('kgInput').value); | ||
result = kg * 2.20462 + ' pounds'; | ||
} else if (conversionType === 'lbToKg') { | ||
const lb = parseFloat(document.getElementById('lbInput').value); | ||
result = lb / 2.20462 + ' kilograms'; | ||
} else if (conversionType === 'gToOz') { | ||
const g = parseFloat(document.getElementById('gInput').value); | ||
result = g / 28.3495 + ' ounces'; | ||
} else if (conversionType === 'ozToG') { | ||
const oz = parseFloat(document.getElementById('ozInput').value); | ||
result = oz * 28.3495 + ' grams'; | ||
} else if (conversionType === 'kgToG') { | ||
const kg = parseFloat(document.getElementById('kgInput').value); | ||
result = kg * 1000 + ' grams'; | ||
} else if (conversionType === 'lbToOz') { | ||
const lb = parseFloat(document.getElementById('lbInput').value); | ||
result = lb * 16 + ' ounces'; | ||
} else if (conversionType === 'gToLb') { | ||
const g = parseFloat(document.getElementById('gInput').value); | ||
result = g / 453.592 + ' pounds'; | ||
} else if (conversionType === 'lbToG') { | ||
const lb = parseFloat(document.getElementById('lbInput').value); | ||
result = lb * 453.592 + ' grams'; | ||
} else if (conversionType === 'ozToKg') { | ||
const oz = parseFloat(document.getElementById('ozInput').value); | ||
result = oz / 35.274 + ' kilograms'; | ||
} else if (conversionType === 'kgToOz') { | ||
const kg = parseFloat(document.getElementById('kgInput').value); | ||
result = kg * 35.274 + ' ounces'; | ||
} | ||
|
||
document.getElementById('result').innerText = 'Result: ' + result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters