Skip to content

03 Debugging

F-Gholami edited this page Jul 22, 2020 · 3 revisions

Fix a Typo error

A typo error has been fixed; an extra "d" has been removed from the function name addItem() (controller.js line 95)

Controller.prototype.addItem = function (title) { 
	var self = this;

	if (title.trim() === '') {
		return;
	}

	self.model.create(title, function () {
		self.view.render('clearNewTodo');
		self._filter(true);
	});
};

Generate a unique ID

There was a risk of creating duplicate Id in the previous way of generating the ID, therefore, for having a unique ID we can simply get the current date and time and assign it to each item. (store.js line 91)

var newId = new Date().getTime()

Optimizing the code

  • Changing the if statement into a ternary (model.js line 105)
todo.completed) ? todos.completed++ : todos.active++
  • Removing unnecessary logging statement (controller.js lines 165 to 169)
items.forEach(function(item) {
	if (item.id === id) {
		console.log("Element with ID: " + id + " has been removed.");
	}
});

Clone this wiki locally