diff --git a/js-essentials/dragon-trainer-monthly/README.md b/js-essentials/dragon-trainer-monthly/README.md new file mode 100644 index 0000000..77500ff --- /dev/null +++ b/js-essentials/dragon-trainer-monthly/README.md @@ -0,0 +1,10 @@ +# Random Ron + +A site that displays a random Ron Swanson quote (from the show Parks +and Recreation) using the [Ron Swanson Quotes +API](https://github.com/jamesseanwright/ron-swanson-quotes). + +# Reference + +* https://leanwebclub.com/learn/js-essentials/project-random-ron + diff --git a/js-essentials/dragon-trainer-monthly/index.html b/js-essentials/dragon-trainer-monthly/index.html new file mode 100644 index 0000000..ce03195 --- /dev/null +++ b/js-essentials/dragon-trainer-monthly/index.html @@ -0,0 +1,14 @@ + + + + + + + Dragon Trainer Monthly + + +

Dragon Trainer Monthly

+
+ + + diff --git a/js-essentials/dragon-trainer-monthly/script.js b/js-essentials/dragon-trainer-monthly/script.js new file mode 100644 index 0000000..59b18b4 --- /dev/null +++ b/js-essentials/dragon-trainer-monthly/script.js @@ -0,0 +1,34 @@ +let app = document.querySelector('#app'); +let endpoint = 'https://vanillajsacademy.com/api/dragons.json'; + +async function getArticles() { + app.innerHTML = 'Fetching articles...'; + + try { + let response = await fetch(endpoint); + if (!response.ok) throw response.status; + + let dragons = await response.json(); + if (!dragons) throw 'no data'; + + app.innerHTML = dragons.articles.map(function(item) { + return ` +

${item.title}

+${item.pubdate} by ${item.author} +

${item.article}

+
+` + }).join(''); + + } catch (error) { + console.warn(error); + } +} + +getArticles(); + + + + + + diff --git a/js-essentials/main.go b/js-essentials/main.go index 1bde255..db5900f 100644 --- a/js-essentials/main.go +++ b/js-essentials/main.go @@ -17,6 +17,7 @@ func main() { mux.Handle("GET /random-ron/", http.StripPrefix("/random-ron", http.FileServer(http.Dir("random-ron")))) mux.Handle("GET /random-ron-no-dup/", http.StripPrefix("/random-ron-no-dup", http.FileServer(http.Dir("random-ron-no-dup")))) mux.Handle("GET /random-ron-async-await/", http.StripPrefix("/random-ron-async-await", http.FileServer(http.Dir("random-ron-async-await")))) + mux.Handle("GET /dragon-trainer-monthly/", http.StripPrefix("/dragon-trainer-monthly", http.FileServer(http.Dir("dragon-trainer-monthly")))) log.Println("Start the web server...") err := http.ListenAndServe(":8080", mux)