Skip to content

Commit d1bd85e

Browse files
committed
add code to pass test for "No Todos" fixes #56
1 parent 93f00d0 commit d1bd85e

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

Diff for: examples/todo-list/todo-app.js

+21-8
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,13 @@ function render_item (item) {
8282
* @return {Object} <section> DOM Tree which containing the todo list <ul>, etc.
8383
*/
8484
function render_main (model) {
85+
86+
// Requirement #1 - No Todos, should hide #footer and #main
87+
var display = "style=display:"
88+
+ (model.todos.length > 0 ? + "block" : "none");
89+
8590
return (
86-
section(["class=main", "style=display: block;"], [
91+
section(["class=main", "id=main", display], [ // hide if no todo items.
8792
input(["id=toggle-all", "class=toggle-all", "type=checkbox"], []),
8893
label(["for=toggle-all"], [ text("Mark all as complete") ]),
8994
ul(["class=todo-list"],
@@ -104,15 +109,23 @@ function render_main (model) {
104109
* var DOM = render_footer(model);
105110
*/
106111
function render_footer (model) {
107-
var count = model.todos.filter(
108-
function (i) { return i.done === false }
109-
).length.toString();
112+
113+
// Requirement #1 - No Todos, should hide #footer and #main
114+
var display = "style=display:"
115+
+ (model.todos.length > 0 ? + "block" : "none");
116+
117+
// count how many "active" (not yet done) items by filtering done === false:
118+
var count = model.todos.filter( function (i) { return !i.done; }).length;
119+
120+
// number of completed items:
121+
var done = model.todos.length - count;
122+
var display_clear_complete = "style=display:"
123+
+ (model.todos.length > 0 ? + "block" : "none");
110124
// pluarisation of number of items:
111-
var left = (" item" +
112-
(model.todos.length > 1 || model.todos.length === 0 ? 's' : '') + " left");
125+
var left = (" item" + (count > 1 || count === 0 ? 's' : '') + " left");
113126

114127
return (
115-
footer(["class=footer", "style=display: block;"], [
128+
footer(["class=footer", "id=footer", display], [
116129
span(["class=todo-count", "id=count"], [
117130
strong(count),
118131
text(left)
@@ -128,7 +141,7 @@ function render_footer (model) {
128141
a(["href=#/completed"], [text("Completed")])
129142
])
130143
]), // </ul>
131-
button(["class=clear-completed", "style=display:block;"],
144+
button(["class=clear-completed", display_clear_complete],
132145
[text("Clear completed")]
133146
)
134147
])

Diff for: todo-list.md

+12
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,18 @@ You should see the following output:
14091409

14101410
##### Make it Pass!
14111411

1412+
Simply replace the instances of `"style=display: block;"` in the view code
1413+
with a reference to a "_computed style_" e.g:
1414+
1415+
```js
1416+
// Requirement #1 - No Todos, should hide #footer and #main
1417+
var display = "style=display:"
1418+
+ (model.todos.length > 0 ? + "block" : "none");
1419+
```
1420+
1421+
You should see:
1422+
![no-todos-test-passing](https://user-images.githubusercontent.com/194400/43868724-e3e2249c-9b66-11e8-8228-a5c1528c17b0.png)
1423+
14121424

14131425

14141426

0 commit comments

Comments
 (0)