When the page is reloaded, totalSubs returns back to its original value of 10. Why is this?
var totalSubs = 10;
window.onload = function getSubs() {
document.getElementById('subsNo').textContent= totalSubs;
}
function runSubs() {
var subsNo = Number(document.getElementById('subsNo').textContent);
var NewSubsNo = 0;
NewSubsNo = subsNo + 1;
document.getElementById('subsNo').textContent= NewSubsNo;
return NewSubsNo;
}
totalSubs = runSubs(totalSubs);
<input type="submit" value="Subscribe" style="width:200px; height:60px; font-size: 2.0rem;" onclick="runSubs()" onload="getSubs()" />
<p id="subsNo"> </p>
Backend:
var http = require('http');
var fs = require('fs');
http.createServer(function (req, res) {
fs.readFile('MobileUI.html', function(err, data) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data);
return res.end();
});
}).listen(8080);
Store it in the localStorage of a web browser. Currently, you are storing in temporary memory so instead, use local storage.
localStorage.setItem('totalSub', 10);
const getSub = local.getItem('totalSub')