Skip to content

Instantly share code, notes, and snippets.

@bmacmill
Created April 21, 2017 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bmacmill/145c43f792da42f6caf28796d291e179 to your computer and use it in GitHub Desktop.
Save bmacmill/145c43f792da42f6caf28796d291e179 to your computer and use it in GitHub Desktop.
// curious what this is doing? https://learn.jquery.com/using-jquery-core/document-ready/
//bn notes: kind of a mess, lots of notes by myself you can ignore, couldn't get focus to work??? :/
$(document).ready(function() {
// write your code here
/*You should be working in `app.js` in `homeworks/homework-02/js`. I commented out the
predefined list items in index.html because the todolist is empty when
the page starts. You need to use those list items as a reference for
the html that's to be inserted onto the page.
*/
//Implement "No todos" and "New todos" following the guidelines listed here:
/*No todos
1. When there are no todos, #main and #footer should be hidden.*/
/*
New todos are entered in the input at the top of the app.
1. The input element should be focused when the page is loaded, preferably by using the !!autofocus
input attribute.
--can't get autofocus to work??
done-2. Pressing Enter creates the todo, appends it to the todo list,
and clears the input.
done--3. Make sure to !!!.trim() the input and then check that its
not empty before creating a new todo.*/
//think this kind of works a bit...
// var todoText;
$( "footer" ).hide();
$(".new-todo").keypress(function(event){
if(event.which === 13) {
//grabbing new todo text from input
var todoText = $(this).val().trim();
if (todoText === '') {
alert("enter a todo");
} else {
//create a new li and add to ul
//not sure how to add a class so it looks right???
//adding class to li breaks everything
//adding label half works, but know prob this isn't correct
$(".todo-list").append("<li><label>" + todoText + "</label></li>");
$( "footer" ).show();
}
//this empty string clears the text field after enter not sure if this is right place for it
$(this).val("");
}
});
});
@donoage
Copy link

donoage commented Apr 24, 2017

Hey Brian, see here for my comments. https://gist.github.com/donoage/9df4f9b2ec6bf75d30f3b71ba47a36fb

Be sure add the extension .js when you're creating gists and also format your code so your indentations are correct for readability.

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