facn6 / Api-project

0 stars 1 forks source link

Repeated Code #20

Open samjam48 opened 5 years ago

samjam48 commented 5 years ago

Lines 67-80. This code is very repeated. It could be abstracted into a separate function to clean up this first function. It could also be done more smartly mapping over children of the parent div. You could then build an array beforehand of the properties to put into each box and combine the two in the map function.

https://github.com/facn6/Api-project/blob/b1a936e4d03c04e491afc99af8065e86df886657/JS.js#L67

samjam48 commented 5 years ago

Also in the HTML you have repeated code for every card.

This is like 70 lines of code which makes the document quite long for just a small part of the site. Imagine you had a bigger site you quickly have a very long document.

Each card has a set formula to create it. So why not put that formula in a function and create the flags in ten lines of javascript instead?

function renderCards () {
  let cards = ['Languages', 'Population',  // etc... ]
  let html = cards.map(function(card){
     return '<div id="' + card +'">'
           + '<p>' // etc......
  } 

  // put html in doc here

}