I just need a way to decrement the coins of the user every time the page is refreshed. This is my program:
var http = require('http');
var coins = 100;
var server = http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write("Hello World");
coins -= 1;
res.write('Your coins: ' + coins + '\n');
res.end();
})
server.listen(1338, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1338/');
This is what I get every time I refresh the page:
Your coins: 99
Your coins: 97
Your coins: 95
Your coins: 93
Your coins: 91
Your coins: 89
Your coins: 87
...
As you can see, it decrements by 2 instead of 1. Why?