You are declaring new variable every time a function is called. Also, try avoiding naming your variables '$', because a lot of JS tools/libs use this character as their identifier (ex. jQuery heavily uses $).
Here is a slightly edited JavaScript for your example:
Code:
var wallet = 5; // set initial wallet value to 5
function myFunction()
{
document.getElementById("demo").innerHTML = wallet;
}
function addMoney()
{
wallet++; // increments by 1
document.getElementById("add").innerHTML = "New value: " + wallet;
}
Bookmarks