I am currently trying to perform some simple actions on a variable that I've given the value of zero. First of all, I am declaring a variable and giving it a value (0). Secondly, I am creating a function which is supposed to increment the value of my variable when the function is invoked. This is my code:
var orderCount = 0;
function takeOrder(orderCount) {
return orderCount++;
}
takeOrder(orderCount);
takeOrder(orderCount);
alert(orderCount);
The exptected result of the code snippet above would be "2", since the function is invoked twice and the number 0 therefore should be incremented twice.
I have also tried incrementing the variable "orderCount" with the following code instead of the one posted above:
function takeOrder(orderCount) {
return orderCount + 1;
}
Neither works. What am I doing wrong?