diff --git a/labs/lab-axios-functional-programming/starter-code/api.js b/labs/lab-axios-functional-programming/starter-code/api.js index 32843a1..7d8d4e1 100644 --- a/labs/lab-axios-functional-programming/starter-code/api.js +++ b/labs/lab-axios-functional-programming/starter-code/api.js @@ -14,7 +14,8 @@ function getTotalResults(page) { .then(response => { // TODO: Iteration 1 // Update that function so it only displays the value of "total_results" (18966) - return response.data // You should write it "response.data.something" + return response.data.total_results; + // You should write it "response.data.something" }) } @@ -23,7 +24,7 @@ function getFirstResultName(page) { .then(response => { // TODO: Iteration 2 // Update that function so it only displays the name of the first actor - return response.data + return response.data.results[0].name; }) } @@ -31,27 +32,68 @@ function getNames(page) { return service.get(`page-${page}.json`) .then(response => { // TODO: Iteration 3 + let results = response.data.results; + console.log(results); + let nameResults = results.map( el => { + return el.name + + } + ) + return nameResults; }) } function getIdsAndNames(page) { return service.get(`page-${page}.json`) .then(response => { - // TODO: Iteration 4 + // TODO: Iteration 3 + let results = response.data.results; + console.log(results); + let nameResults = results.map( el => { + return "#" + el.id + " "+ el.name + + } + ) + return nameResults; }) } function getSortedNames(page) { return service.get(`page-${page}.json`) .then(response => { - // TODO: Iteration 5 + // TODO: Iteration 3 + let results = response.data.results; + console.log(results); + let nameResults = results.map( el => { + return el.name + + } + ) + return nameResults; + }) + .then (nameResults => { + return nameResults.sort(); }) } function getNamesFiltered(page, searchTerm) { return service.get(`page-${page}.json`) .then(response => { - // TODO: Iteration 6 + // TODO: Iteration 3 + let results = response.data.results; + console.log(results); + let nameResults = results.map( el => { + return el.name + + } + ) + return nameResults; + }) + .then (nameResults => { + let filteredNames = nameResults.filter(actName => { + return actName.toUpperCase().includes(searchTerm.toUpperCase()); + }); + return filteredNames; }) }