Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Nick Marsh
14,255 PointsTo do list using JavaScript
Hello all,
I've been working on a to do list that uses a lot of JavaScript. Recently, I have come across some problems and some things that I would like to do with it but am having trouble doing.
I put it on github - https://github.com/nmarsh33/Simple-To-Do-List
I know there is a course on treehouse that walks you through the building of a to do list application. After going through that course, I know mine is unnecessarily more complex.
My current problem is getting 2 of of my JavaScript files to communicate correctly. I have a file that handles most of the action and another one that is loaded if the user has geolocation. The geolocation file will get the coordinates of the user and update them accordingly in the HTML next to the to do item.
This is some of the geolocation file. I keep getting the error cannot read 'coords' property of the undefined.
function sendLocation(todoItem, position) {
var crds = position.coords;
getLocation(todoItem, crds);
}
//Handles the success call for geolocation
function findLocation() {
navigator.geolocation.getCurrentPosition(getLocation,locationError);
}
function getLocation(todoItem, position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
todoItem.latitude = latitude;
todoItem.longitude = longitude;
if (!map) {
showMap(latitude, longitude);
}
addMarker(latitude, longitude);
}
And this is the code where I am sending the to do list item in question along with its position
function getFormData() {
var task = document.getElementById("task").value;
if (checkInputText(task, "Please enter a task")) return;
var who = document.getElementById("who").value;
if (checkInputText(who, "Please enter a person to do the task")) return;
var date = document.getElementById("dueDate").value;
if (checkInputText(date, "Please enter a due date")) return;
// later, process date here
var latitude=null;
var longitude=null;
var id = (new Date()).getTime();
var todoItem = new Todo(id, task, who, date, latitude, longitude);
todos.push(todoItem);
addTodoToPage(todoItem);
saveTodoItem(todoItem);
findLocation(todoItem);
sendLocation(todoItem);
// hide search results
hideSearchResults();
}
Any help would be much appreciated.
Marcus Parsons
15,718 PointsMarcus Parsons
15,718 PointsHey man, if it helps any, I created a persistent to-do list app that you can check out here. The code has quite a few comments in the "app.js" file. http://marcusparsons.com/projects/todolist/index.html