Skip to content

Commit

Permalink
Fixed negative inputs in Antilog Calculator (#912)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aarzookhunger authored May 27, 2024
1 parent 44ced19 commit 5d043ac
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
7 changes: 5 additions & 2 deletions Calculators/Antilog-Calculator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ <h1>Antilog Calculator</h1>
<hr>
<div class="content">
<p>Calculate the antilog of any number to any base:</p>
<div id="number1"><input type="number" id="number" placeholder="Enter number"></div>
<div id="base1"><input type="number" id="base" placeholder="Enter base" default="10"></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="calculateAntilog()" id="button">Calculate Antilog</button>
<h3>Result:</h3>
<h3 id="resultb"></h3>
Expand Down
9 changes: 9 additions & 0 deletions Calculators/Antilog-Calculator/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,13 @@ function calculateAntilog() {
} else {
alert('Invalid input. Please enter positive numbers greater than 0 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';
}
}
25 changes: 23 additions & 2 deletions Calculators/Antilog-Calculator/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ body {
margin: 0;
padding: 0;
font-size: 20px;
background-color: rgb(113, 105, 201);
background-image: linear-gradient(to right,rgb(113, 105, 201),rgb(175, 169, 169));
}

#heading {
text-align: center;

}

.content {
Expand All @@ -24,16 +23,38 @@ body {
}

#base {
border: solid 2px black;
border-radius: 5px;
padding: 10px 15px 10px 10px;
margin-bottom: 15px;
}


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

#number {
border: solid 2px black;
border-radius: 5px;
padding: 10px 15px 10px 10px;
margin-bottom: 10px;
}

#button {
margin-top: 20px;
padding: 20px 20px 20px 20px;
font-size: 20px;
border: solid 3px black;
border-radius: 5px;
background-color: rgb(113, 105, 201);
transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

#button:hover{
border: none;
background-color: white;
box-shadow: 3px 3px 3px rgb(113, 105, 201);
}

0 comments on commit 5d043ac

Please sign in to comment.