`Why does it work outside the function tho? What’s wrong? I dont get it… Tried adding return statemnts – still nothing. [[enter image description here](https://phpout.com/wp-content/uploads/2023/09/ZWAvj.png)](https://phpout.com/wp-content/uploads/2023/09/HteFI.png)
DOESN’T WORK:
function changeValue() {
let charge = document.getElementById("myRange").value;
document.getElementById("displayValue").innerHTML = charge;
}
WORKS:
let charge = document.getElementById("myRange").value;
document.getElementById("displayValue").innerHTML = charge;
my HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Battery Emulatior</title>
<link rel="icon" type="image/x-icon" href="favicon.png">
<link rel="stylesheet" href="battery.css">
</head>
<body>
<h1>INTERACTIVE BATTERY EMULATOR</h1>
<p1>Choose the expiration period</p1>
<div class="indicator">
<div class="batteryterminal"></div>
</div>
<div class="slidecontainer">
<input type="range" min="1" max="100" value="50" class="slider" id="myRange">
</div>
<div id="displayValue"></div>
<script src="battery.js"></script>
</body>
</html>
`
tried adding return statements – nothing
2
Answers
You need to call the function for it to execute