When I perform an addition operation in JavaScript, instead of getting the expected result of 4.5 + .525 = 5.025, I receive 4.5.525.
Here is the code snippet:
<!DOCTYPE html>
<html lang="en">
...
<button class= "btn btn-danger" style="margin: 2%;
text-align: center;
;
margin-top: 5%;" onclick="refreshPage()">Reset All</button>
</div>
<script>
function refreshPage(){
window. location. reload();
}
</script>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
...
function Calculate() {
let vl = document.getElementById('VL').value;
let il = document.getElementById('IL').value;
let ish = document.getElementById('Ish').value;
let ra = document.getElementById('Ra').value;
let ld = document.getElementById('Load').value;
let vlo = document.getElementById('noLoad').value;
let SI = (vl * ld)
...
var ef = (SI / OP) * 100
document.getElementById('Eff').innerHTML = " η % : " + ef;
}
</script>
<script>
function myFunction() {
var element = document.body;
element.classList.toggle("dark-mode");
}
</script>
</html>
After setting IL to 4.5 and Ish to .525, the console output incorrectly shows 4.5.525 instead of 5.025.
To address this issue, rewrite and comment the code accordingly for clarity.
In contrast, entering the same values directly into a JavaScript calculation yields the correct answer.