-2

I am creating a todo app with javascript. I am trying to set a variable call ttlTasks that increments whenever a new task is created. However The value in the variable is not incrementing when I do ttlTasks++;. I believe this is because of something wrong in my variable scope but I can not find the error anywhere. Can anyone help me? this is the jsfiddle: http://jsfiddle.net/4bcv82t9/1/ I recommend expanding the result when run the program or visit

http://54.172.112.28/
  • Your fiddle doesn't work but you have a `function addTask(taskTitle, taskDescription, taskTime, ttlTasks){`, you're passing in ttlTasks to this and incrementing it, not the global variable. Simply don't pass it in. – artm Nov 13 '14 at 03:05

1 Answers1

0

It is a scoping issue. The ttlTasks you are incrementing in addTask is actually passed in by value and any changes you make to it are local to the addTask method. There is no reason for you to 'send in' ttlTask into addTask, since you have it declared globally and JavaScript is a pass by value language (see this post)

Community
  • 1
  • 1
codechurn
  • 3,870
  • 4
  • 45
  • 65
  • Thank you so much for refferring me to that link. I've historically always had problems with problems of this nature in the past. Thank you! – Tyler Oliver Nov 13 '14 at 04:24