diff --git a/labs/lab-axios-functional-programming/starter-code/api.js b/labs/lab-axios-functional-programming/starter-code/api.js index 2b5e606..d58ca83 100644 --- a/labs/lab-axios-functional-programming/starter-code/api.js +++ b/labs/lab-axios-functional-programming/starter-code/api.js @@ -1,5 +1,5 @@ let service = axios.create({ - baseURL: "https://raw.githubusercontent.com/mc100s/module-3-react/labs/lab-axios-functional-programming/" + baseURL: "https://raw.githubusercontent.com/mc100s/training-labs-react/master/src/lab-axios-functional-programming" }) function displayDataInTheConsole(page) { @@ -12,10 +12,12 @@ function displayDataInTheConsole(page) { function getTotalResults(page) { return service.get(`page-${page}.json`) .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" + // "total_results" (18966) + return response.data.total_results // You should write it "response.data.something" }) + // .then( result => { + // document.getElementById("getTotalResults").innerHTML = JSON.stringify(result, null, 2) + // }); } function getFirstResultName(page) { @@ -23,7 +25,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,20 +33,21 @@ function getNames(page) { return service.get(`page-${page}.json`) .then(response => { // TODO: Iteration 3 + return response.data.results.map( actor => actor.name); }) } function getIdsAndNames(page) { return service.get(`page-${page}.json`) .then(response => { - // TODO: Iteration 4 + return response.data.results.map( actor => `#${actor.id} ${actor.name}`); }) } function getSortedNames(page) { return service.get(`page-${page}.json`) .then(response => { - // TODO: Iteration 5 + return response.data.results.map( actor => actor.name).sort(); }) } @@ -52,6 +55,7 @@ function getNamesFiltered(page, searchTerm) { return service.get(`page-${page}.json`) .then(response => { // TODO: Iteration 6 + return response.data.results.map( actor => actor.name).filter(name => name.toUpperCase().includes(searchTerm.toUpperCase()) ); }) } @@ -60,5 +64,17 @@ function getActorNamesWithTheirKnownForMovies(page) { return service.get(`page-${page}.json`) .then(response => { // TODO: Iteration 7 + + return response.data.results + .map( actor => + `${actor.name} (${actor.known_for.map( movie => movie.title )})` + ); + }) +} + +function getKnownForMovies(page) { + return service.get(`page-${page}.json`) + .then( response => { + return response.data.results.map( actor => `${actor.known_for.map( movie => movie.title )}` ).sort(); }) } \ No newline at end of file diff --git a/labs/lab-axios-functional-programming/starter-code/dom-manipulation.js b/labs/lab-axios-functional-programming/starter-code/dom-manipulation.js index 6c2d40f..8ccb069 100644 --- a/labs/lab-axios-functional-programming/starter-code/dom-manipulation.js +++ b/labs/lab-axios-functional-programming/starter-code/dom-manipulation.js @@ -1,5 +1,5 @@ // You can change that value, from 1 to 3 -let page = 1 +let page = 2 // You shouldn't modidify the next lines @@ -32,3 +32,6 @@ getNamesFiltered(page, "m") getActorNamesWithTheirKnownForMovies(page) .then(updateTheDom("getActorNamesWithTheirKnownForMovies")) + +getKnownForMovies(page) +.then(updateTheDom("getKnownForMovies")) diff --git a/labs/lab-axios-functional-programming/starter-code/index.html b/labs/lab-axios-functional-programming/starter-code/index.html index 5f3d427..98c9826 100644 --- a/labs/lab-axios-functional-programming/starter-code/index.html +++ b/labs/lab-axios-functional-programming/starter-code/index.html @@ -29,6 +29,10 @@