I am a newcomer to the world of JS and have been following a tutorial. Below is my very simple code.
HTML
<body>
<p>People Entered</p>
<h1 id="count-el">0</h1>
<button id="inc" onclick="increment()">Increment</button>
<button id="rst" onclick="rst()">Reset</button>
<button id="getoff" onclick="getoff()">Get Off</button>
<button id="save" onclick="save()">Save</button>
<p id="save-el">Previous Saves : </p>
<script src="scripts.js"></script>
JS
function save() {
let text = document.getElementById("save-el").innerText
document.getElementById("save-el").innerText = text +" " + count
}
The above JS code provides the exact output I want. But if I change it as follows, it does not provide any output and remains blank.
function save() {
let text = document.getElementById("save-el").innerText
text = text +" " + count
}
I don’t understand why it happens and appreciate it if someone could explain what I am missing here. Thanks in advance.