Skip to content

Commit

Permalink
Bug : Negative input in logarithmic calculator fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Aarzookhunger committed May 19, 2024
1 parent 22c3c46 commit 3613dbc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
6 changes: 4 additions & 2 deletions Calculators/Logarithm-Calculator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ <h1>Logarithm Calculator</h1>
<hr>
<div class="content">
<p>Calculate Logarithm of a number to any base:</p>
<div id="base1"><input type="number" id="base" placeholder="Enter base"></div>
<div id="number1"><input type="number" id="number" placeholder="Enter number"></div>
<div id="number1"><input type="number" id="number" min="0" step="any" oninput="validity.valid && value!=0 || (value='');" placeholder="Enter number" required></div>

<div id="base1"><input type="number" id="base" min="0.000001" step="any" oninput="validity.valid && value!=0 || (value='');" onchange="validateBaseInput(this)" placeholder="Enter base" required><br><span id="baseError">INVALID INPUT *Base can't be 1*</span></div>

<button onclick="calculateLog()" id="button">Calculate Log</button>
<h3>Result:</h3>
<p id="result"></p>
Expand Down
9 changes: 9 additions & 0 deletions Calculators/Logarithm-Calculator/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@ function calculateLog() {
} else {
alert('Invalid input. Please enter positive numbers for both the base and the number, and ensure that the base is not equal to 1.')
}
}

function validateBaseInput(base) {
const errorElement = document.getElementById('baseError');
if (base.value == 1) {
errorElement.style.display = 'inline';
} else {
errorElement.style.display = 'none';
}
}
8 changes: 7 additions & 1 deletion Calculators/Logarithm-Calculator/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ body {

#heading {
text-align: center;

}

.content {
Expand All @@ -28,12 +27,19 @@ body {
margin-bottom: 15px;
}

#baseError {
color: rgb(241, 63, 63);
display: none;
font-size : 15px ;
}

#number {
padding: 10px 15px 10px 10px;
margin-bottom: 10px;
}

#button {
margin-top: 20px;
padding: 20px 20px 20px 20px;
font-size: 20px;
}

0 comments on commit 3613dbc

Please sign in to comment.