Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed negative inputs in Logarithmic Calculator #774

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}