Skip to content

Commit

Permalink
Feat/AC-to-DC-Calculator
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgaharwal committed Dec 29, 2024
1 parent 2063690 commit 4f4c520
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 0 deletions.
Binary file not shown.
33 changes: 33 additions & 0 deletions Calculators/AC-to-DC-Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>AC to DC Converter Calculator</title>
<link rel="stylesheet" href="style.css" />
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
</head>
<body>
<div class="calculator">
<h1>AC to DC Converter Calculator</h1>
<p class="formula">
Formula:
<span id="latex-formula">\( V_{DC} = \frac{V_{AC}}{\sqrt{2}} \)</span>
</p>

<label for="vac"
>Enter AC Voltage <span id="latex-formula"> \( V_{AC} \)</span>:</label
>
<input type="number" id="vac" placeholder="Enter AC Voltage (in volts)" />

<div class="buttons">
<button onclick="calculateDC()">Calculate</button>
<button onclick="clearInputs()">Clear</button>
</div>

<div class="result" id="result"></div>
</div>
<script src="script.js"></script>
</body>
</html>
16 changes: 16 additions & 0 deletions Calculators/AC-to-DC-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function calculateDC() {
const vac = parseFloat(document.getElementById('vac').value);

if (isNaN(vac)) {
document.getElementById('result').innerText = "Please enter a valid AC voltage.";
return;
}

const vdc = vac / Math.sqrt(2);
document.getElementById('result').innerText = `DC Voltage (Vₙ): ${vdc.toFixed(2)} V`;
}

function clearInputs() {
document.getElementById('vac').value = '';
document.getElementById('result').innerText = '';
}
85 changes: 85 additions & 0 deletions Calculators/AC-to-DC-Calculator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
body {
font-family: 'Roboto', sans-serif;
background-image: url('/Calculators/AC-to-DC-Calculator/assest/phy_background.webp');
background-size: cover;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
color: #333;
}

.calculator {
background: rgba(255, 255, 255, 0.95);
padding: 30px;
border-radius: 10px;
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
width: 400px;
text-align: center;
}

h1 {
font-size: 28px;
margin-bottom: 20px;
color: #007bff;
}

.formula {
font-size: 16px;
margin-bottom: 20px;
color: #555;
}

label {
font-size: 14px;
margin: 10px 0 5px;
display: block;
text-align: left;
}

input {
width: calc(100% - 20px);
padding: 10px;
margin-bottom: 15px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 5px;
}

.buttons {
display: flex;
justify-content: space-between;
}

button {
background-color: #007bff;
color: white;
padding: 12px 20px;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
margin: 5px;
flex: 1;
}

button:hover {
background-color: #0056b3;
}

.result {
margin-top: 20px;
font-size: 18px;
font-weight: bold;
color: #333;
}

button:last-child {
background-color: #dc3545;
}

button:last-child:hover {
background-color: #b02a37;
}

0 comments on commit 4f4c520

Please sign in to comment.