From f1d3eb3a0c71889b99acb6988978d32e7fe5209d Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Mon, 6 Aug 2018 16:17:25 -0400 Subject: [PATCH] By Reviewer: Maybe nice to explain why we will get an error? --- BUILD.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/BUILD.md b/BUILD.md index d25bcdd..1db2f52 100644 --- a/BUILD.md +++ b/BUILD.md @@ -730,7 +730,17 @@ If you try to delete all the circles and then add a new one, you'll get an error ![](https://i.imgur.com/FprJXNN.png) -Inside the `` click handler, let's put in a little code to handle when the user has deleted all runs and tries to add a new one: +This is because, our code for creating a `newRun` in the click handler needs some work: + +```javascript +var newRun = { //create a new "run" object + id: runs[runs.length-1].id+1, //generate a new id by adding 1 to the last run's id + date: formatTime(date), //format the date object created above to a string + distance: distance //add the distance +} +``` + +`runs[runs.length-1]` tries to access an element at index -1 in the array. Inside the `` click handler, let's put in a little code to handle when the user has deleted all runs and tries to add a new one: ```javascript //inside svg click handler