Looking for some project feedback on my Wikipedia Viewer. It’s very basic design, not really appealing, but what I am really interested in is feedback on my Javascript. I can redesign the html/css later to make it look nice. Any advice is appreciated. Thanks!

In your getJSON callback function, your use of the ternary operator as an if then really is not what is was intended for. You can still use it, but use it to assign a value to something. For example, you current code below calls one of two functions. The first function, appends “No Result” if the API did not return anything. The seconds uses a map to append each article.

Each time use use append, the screen has to re-render which takes some resources and slows down the page just a bit (not enough when displaying 10 results like you have but what if it was 100 results?). A better way is have each of these functions return a string up html that you will ultimately append one time at the very end of the getJSON callback function. This string would be assigned to a variable (let’s call it results) using the ternary operator similar to what you have already done.

The biggest change I suggest is to not us the map function to iterate over the array and append each article. Instead, use the reduce function to return a string with all the html needed to append to the “data” div.

I have provided a way to do what I have described below (blurred out). One other thing you will notice in the displaySearch and noResults functions is my use of Template Literals. They make it easier to format/read the html string created. You should get familiar with this functionality and start using it in all of your projects.

Do not click on these solutions if you want to try and implement my suggestions first. If you have any questions or need clarification about anything I have suggested or written in the code below, please ask.

No console errors on the developer tools. I changed the first grave tick to the same line with the ‘return’ word and it started working, however, it’s only displaying the last index of the array instead of all the indexes. Maybe I need to change the reduce function?