var generateProposalHTML = function(proposal) {
var listItem = document.createElement('li');
- listItem.innerHTML = proposal.title + ' (' + proposal.total_occurrences + ' votes) <a href="#" onclick="createProposal(\'' + proposal.title.replace(/'/g, '\\\'')+ '\')">I agree.</a> </li>'
+ listItem.innerHTML = proposal.title + ' (' + proposal.total_occurrences + ' votes) <a href="#add-' + proposal.id + '" onclick="createProposal(\'' + proposal.title.replace(/'/g, '\\\'')+ '\')">I agree.</a> </li>'
return listItem;
};
const container = document.getElementById('proposals');
- parsedResponse.result.items.forEach((proposal) => {
+ parsedResponse.result.items
+ .sort((a, b) => b.total_occurrences - a.total_occurrences)
+ .forEach((proposal) => {
container.appendChild(generateProposalHTML(proposal));
});