Understanding promises

This commit is contained in:
2017-02-14 00:32:39 -08:00
parent 74146a17ee
commit aa4d767204
8 changed files with 300 additions and 2 deletions

10
js/ratefinder.js Normal file
View File

@@ -0,0 +1,10 @@
let url = "rates.json";
fetch(url)
.then(response => response.json())
.then(rates => {
let html = '';
rates.forEach(rate => html += `<tr><td>${rate.name}</td><td>${rate.years}</td><td>${rate.rate}%</td></tr>`);
document.getElementById("rates").innerHTML = html;
})
.catch(e => console.log(e));