4. Bug fixing - robgillibrand/Todo-List-App GitHub Wiki

Bug 1 found in controller.js

From this: self.view.bind('newTodo', function (title) { self.adddItem(title); });

To this: self.view.bind('newTodo', function (title) { self.addItem(title); });

There was an extra 'd' in the add item function, which meant you couldn't add any todos to the list.

Bug 2 found in store.js

From this: var newId = ""; var charset = "0123456789"; for (var i = 0; i < 6; i++) { newId += charset.charAt(Math.floor(Math.random() * charset.length)); }

To this: var newId = ""; newId += Date.now()

I've changed the function for 'setting an id number for a todo', because of the chance of duplication and having to loop through each time. With the math.random function there is still a chance that a todo could end up with the same id. The Date.now() method returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC so can never be repeated, also the code is less verbose.

Observation

While fixing the bugs and looking through the code, I noticed that when an item is removed from the list, the ID number is outputted to the Console Log. I'm not sure if this is necessary, and if removed would help to reduce the code.