Skip to content

Instantly share code, notes, and snippets.

@rachel-yankelevitz
Created April 21, 2017 03:34
Show Gist options
  • Save rachel-yankelevitz/b46016206eab9bfb6ed7399c9508475e to your computer and use it in GitHub Desktop.
Save rachel-yankelevitz/b46016206eab9bfb6ed7399c9508475e to your computer and use it in GitHub Desktop.
HW 2
$(document).ready(function(){
var todoCollection = [];
$(".main, .footer").hide();
$(".new-todo").keypress(function(e) {
// enter key's key number is 13
if (e.which === 13 && $(this).val().length > 1){
var todoInput = $(".new-todo").val();
$.trim(todoInput);
var todoId = _.uniqueId();
var todoObj = {
id: todoId,
content: todoInput,
completed: false
};
todoCollection.push(todoObj);
console.log(todoCollection);
var listItem = "<li data-id=" + todoId + ">" + todoInput + "</li>";
$(".main, .footer").show();
$(".todo-list").append(listItem);
//mark all as complete
$(".clear-completed").bind("click", function() {
$("input[type=text], textarea").val("");
});
}
});
});
@donoage
Copy link

donoage commented Apr 23, 2017

Thoughts,

https://gist.github.com/rachel-yankelevitz/b46016206eab9bfb6ed7399c9508475e#file-app-js-L10

  • $(this).val().length > 1, this part should be 0, not 1 for anything more than 0. You're not adding a new item if someone just typed in one character.

https://gist.github.com/rachel-yankelevitz/b46016206eab9bfb6ed7399c9508475e#file-app-js-L22

Rachel! There isn't much improvement over what we worked on after the class. I know you know you could've done more than this :/

2/4.

-Stephen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment