Skip to content

Commit

Permalink
Added Work unit conversion in Unit Calculator (#1752)
Browse files Browse the repository at this point in the history
  • Loading branch information
techy4shri authored Aug 8, 2024
1 parent ea0a179 commit 9bb22f7
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
6 changes: 5 additions & 1 deletion Calculators/Unit-Calculator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ <h2>Unit Calculator</h2>
<label><input type="radio" name="conversionType" value="length" checked=""> <span>Length</span></label>
<label><input type="radio" name="conversionType" value="area"> <span>Area</span></label>
<label><input type="radio" name="conversionType" value="weight"> <span>Weight</span></label>
<label><input type="radio" name="conversionType" value="work"> <span>Work</span></label> <!--added work option-->
</div>
<div class="radio-group right">
<label><input type="radio" name="conversionType" value="volume"> <span>Volume</span></label>
Expand All @@ -30,7 +31,9 @@ <h2>Unit Calculator</h2>
<option value="kilometer">kilometer</option>
<option value="centimeter">centimeter</option>
<option value="mile">mile</option>
<option value="yard">yard</option>



</select>
<label for="unitTo">To:</label>
<select id="unitTo">
Expand All @@ -39,6 +42,7 @@ <h2>Unit Calculator</h2>
<option value="centimeter">centimeter</option>
<option value="mile">mile</option>
<option value="yard">yard</option>

</select>
<button onclick="convert()">Convert</button>
<h3 id="result">Result: 0</h3>
Expand Down
34 changes: 34 additions & 0 deletions Calculators/Unit-Calculator/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function updateUnitsDropdown(type) {
"square foot",
],
weight: ["kilogram", "gram", "ounce", "pound", "ton"],
work: ["Joule", "electron Volt", "calorie", "kcal", "kWh"], //work units
volume: [
"cubic meter",
"cubic kilometer",
Expand Down Expand Up @@ -164,6 +165,39 @@ function convert() {
pound: (value) => value * 2205,
},
},
work: {
//conversion units for work
Joule: {
"electron-Volt": (value) => value / 1.60218e-19,
calorie: (value) => value / 4.184,
kcal: (value) => value / 4184,
kWh: (value) => value / 3.6e6
},
"electron Volt": {
Joule: (value) => value * 1.60218e-19,
calorie: (value) => value * 1.60218e-19 / 4.184,
kcal: (value) => value * 1.60218e-19 / 4184,
kWh: (value) => value * 1.60218e-19 / 3.6e6
},
calorie: {
Joule: (value) => value * 4.184,
"electron Volt": (value) => value * 4.184 / 1.60218e-19,
kcal: (value) => value / 1000,
kWh: (value) => value * 4.184 / 3.6e6
},
kcal: {
Joule: (value) => value * 4184,
"electron Volt": (value) => value * 4184 / 1.60218e-19,
calorie: (value) => value * 1000,
kWh: (value) => value * 4184 / 3.6e6
},
kWh: {
Joule: (value) => value * 3.6e6,
"electron-Volt": (value) => value * 3.6e6 / 1.60218e-19,
calorie: (value) => value * 3.6e6 / 4.184,
kcal: (value) => value * 3.6e6 / 4184
}
},
volume: {
// Conversion factors for volume units
"cubic meter": {
Expand Down
2 changes: 1 addition & 1 deletion Calculators/Work-Calculator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ <h1>Work Calculator</h1>
</div>
<script src="script.js"></script>
</body>
</html>
</html>
1 change: 0 additions & 1 deletion Calculators/Work-Calculator/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ document.getElementById('workForm').addEventListener('submit', function(e) {
document.getElementById('result').style.color = 'green';
}
});

2 changes: 1 addition & 1 deletion Calculators/Work-Calculator/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ button:hover {
align-items: center;
border:solid;
border-radius: 10px;
height:4vh;
height:4vh;
margin-top: 20px;
font-size: 1.2em;
color: red;
Expand Down

0 comments on commit 9bb22f7

Please sign in to comment.