-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59ba2b1
commit 7a3192f
Showing
6 changed files
with
85 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
function calculateAntilog() { | ||
const number = parseFloat(document.getElementById('number').value); | ||
const base = parseFloat(document.getElementById('base').value); | ||
const number = parseFloat(document.getElementById('number').value); | ||
const base = parseFloat(document.getElementById('base').value); | ||
|
||
if (!isNaN(number) && !isNaN(base) && number > 0 && base > 0 && base !== 1) { | ||
const result = (base) ** (number); | ||
document.getElementById('resultb').innerText = `${result}`; | ||
document.getElementById('result').innerText = `Antilog for base ${base} of ${number} is ${result}`; | ||
} 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.') | ||
} | ||
if (!isNaN(number) && !isNaN(base) && number > 0 && base > 0 && base !== 1) { | ||
const result = (base) ** (number); | ||
document.getElementById('resultb').innerText = `${result}`; | ||
document.getElementById('result').innerText = `Antilog for base ${base} of ${number} is ${result}`; | ||
} 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'; | ||
} | ||
const errorElement = document.getElementById('baseError'); | ||
if (base.value == 1) { | ||
errorElement.style.display = 'inline'; | ||
} else { | ||
errorElement.style.display = 'none'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,65 @@ | ||
// functions to convert values | ||
function cgpaToPercentage(cgpa) { | ||
return cgpa * 9.5 | ||
return cgpa * 9.5 | ||
} | ||
|
||
function percentageToCGPA(percentage) { | ||
return percentage / 9.5 | ||
return percentage / 9.5 | ||
} | ||
|
||
// Function to handle conversion and display values | ||
function convertCGPAToPercentage() { | ||
cleanError() | ||
let cgpaInput = parseFloat(document.getElementById('cgpaInput').value) | ||
if (!isNaN(cgpaInput) && cgpaInput >= 0 && cgpaInput <= 10) { | ||
let percentage = cgpaToPercentage(cgpaInput).toFixed(2) | ||
percentageInput.value = percentage | ||
} else { | ||
// resetting values | ||
cgpaInput.value = null | ||
percentageInput.value = null | ||
showError('Invalid CGPA. Please enter a value between 0 and 10.') | ||
} | ||
cleanError() | ||
let cgpaInput = parseFloat(document.getElementById('cgpaInput').value) | ||
if (!isNaN(cgpaInput) && cgpaInput >= 0 && cgpaInput <= 10) { | ||
let percentage = cgpaToPercentage(cgpaInput).toFixed(2) | ||
percentageInput.value = percentage | ||
} else { | ||
// resetting values | ||
cgpaInput.value = null | ||
percentageInput.value = null | ||
showError('Invalid CGPA. Please enter a value between 0 and 10.') | ||
} | ||
} | ||
|
||
function convertPercentageToCGPA() { | ||
cleanError() | ||
let percentageInput = parseFloat( | ||
document.getElementById('percentageInput').value | ||
) | ||
if ( | ||
!isNaN(percentageInput) && | ||
percentageInput >= 0 && | ||
percentageInput <= 100 | ||
) { | ||
let cgpa = percentageToCGPA(percentageInput).toFixed(2) | ||
// for too low percentage cgpa goes negative | ||
if (cgpa < 0) { | ||
showError('Percentage too low') | ||
} else { | ||
cgpaInput.value = cgpa | ||
} | ||
} else { | ||
// resetting values | ||
cgpaInput.value = null | ||
percentageInput.value = null | ||
showError('Invalid Percentage. Please enter a value between 0 and 100.') | ||
} | ||
cleanError() | ||
let percentageInput = parseFloat( | ||
document.getElementById('percentageInput').value | ||
) | ||
if ( | ||
!isNaN(percentageInput) && | ||
percentageInput >= 0 && | ||
percentageInput <= 100 | ||
) { | ||
let cgpa = percentageToCGPA(percentageInput).toFixed(2) | ||
// for too low percentage cgpa goes negative | ||
if (cgpa < 0) { | ||
showError('Percentage too low') | ||
} else { | ||
cgpaInput.value = cgpa | ||
} | ||
} else { | ||
// resetting values | ||
cgpaInput.value = null | ||
percentageInput.value = null | ||
showError('Invalid Percentage. Please enter a value between 0 and 100.') | ||
} | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', function () { | ||
let cgpaInput = document.getElementById('cgpaInput') | ||
let percentageInput = document.getElementById('percentageInput') | ||
cgpaInput.addEventListener('input', convertCGPAToPercentage) | ||
percentageInput.addEventListener('input', convertPercentageToCGPA) | ||
let cgpaInput = document.getElementById('cgpaInput') | ||
let percentageInput = document.getElementById('percentageInput') | ||
cgpaInput.addEventListener('input', convertCGPAToPercentage) | ||
percentageInput.addEventListener('input', convertPercentageToCGPA) | ||
}) | ||
|
||
function showError(message) { | ||
let error = document.getElementById('error') | ||
error.innerHTML = message | ||
let error = document.getElementById('error') | ||
error.innerHTML = message | ||
} | ||
|
||
function cleanError() { | ||
let error = document.getElementById('error') | ||
error.innerHTML = '' | ||
let error = document.getElementById('error') | ||
error.innerHTML = '' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
function calculateLog() { | ||
const number = parseFloat(document.getElementById('number').value); | ||
const base = parseFloat(document.getElementById('base').value); | ||
const number = parseFloat(document.getElementById('number').value); | ||
const base = parseFloat(document.getElementById('base').value); | ||
|
||
if (!isNaN(number) && !isNaN(base) && number > 0 && base > 0 && base !== 1) { | ||
const result = Math.log(number) / Math.log(base); | ||
document.getElementById('result').innerText = `Log base ${base} of ${number} is ${result.toFixed(4)}`; | ||
} 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.') | ||
} | ||
if (!isNaN(number) && !isNaN(base) && number > 0 && base > 0 && base !== 1) { | ||
const result = Math.log(number) / Math.log(base); | ||
document.getElementById('result').innerText = `Log base ${base} of ${number} is ${result.toFixed(4)}`; | ||
} 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'; | ||
} | ||
const errorElement = document.getElementById('baseError'); | ||
if (base.value == 1) { | ||
errorElement.style.display = 'inline'; | ||
} else { | ||
errorElement.style.display = 'none'; | ||
} | ||
} |