Code: Select all
years = [2016, 2012, 2008, 2004, 2000];
years.forEach(function (year) {
var btn = document.getElementById(year);
btn.addEventListener('click', function () {
document.querySelectorAll('.buttons button.active').forEach(function (active) {
active.className = '';
});
btn.className = 'active';
chartOptions.update({
title: {
text: 'Summer Olympics ' + year + ' - Top 5 countries by Gold medals'
},
subtitle: {
text: 'Comparing to results from Summer Olympics ' + (year - 4) + ' - Source: <a href="https://en.wikipedia.org/wiki/' + (year) + '_Summer_Olympics_medal_table">Wikipedia</a>'
},
series: [{
name: year - 4,
data: dataPrev[year].slice()
}, {
name: year,
data: getData(data[year]).slice()
}]
}, true, false, {
duration: 800
});
});
});
2) line 3 - years.forEach(function(year) { - forEach gives the following error "'forEach', which lacks return-type annotation, implicitly has an 'any' return type.ts(7010). (method) StarshipsComponent.forEach(): any"
3) line 3 - years.forEach(function(year) { - function and (year) give off a few errors but I'm hoping figuring out the first two will help me solve this one.
There's also errors with the btn.addEventlistener, btn.className, and inside the chartOptions. I think once I fix the forEach some of these will get fixed or at least I'll be able to troubleshoot them. Hopefully I've provided enough info but please let me know if anything else is needed. Any help is GREATLY appreciated.