This may or maynot be a simple question as i have very limited javascript skills. All i want to do is modify a variable in a function then return the new variable value ready for use in the funcion again.
An example of this is with a simple button that each time when clicked will deduct ten points from the variable. like a gradual countdown with each click. The problem is that the variable is not updated each time it is returned.
Maybe my starting approach to javascript is way out, thats why i dont seem to be able to find out much about this. here is the code
<html>
<head>
<script type="text/javascript">
/*starting bank account*/
var bank = "200";
/* i want this function to deduct ten from the starting bank account and update the bank variable */
function Bank(bank) {
var printout = document.getElementById("display_bank_result_here");
bank = bank - 10;
printout.innerHTML = bank;
return bank;
}
</script>
</head>
<body>
<button onclick="Bank(bank)">remove 10 from bank</button>
<p id='display_bank_result_here'></p>
</body>
</html>
A pre-emptive thanks to everyone out there. i hope one day i will have enough skills to return the favour to someone else in my posistion.
Robert
var bank = 200;, edit,but as others have already answered, you don't need to pass it via the function parameter, as it's already got "global scope"