diff --git a/js-essentials/main.go b/js-essentials/main.go index 7e01c45..f3ec7f0 100644 --- a/js-essentials/main.go +++ b/js-essentials/main.go @@ -14,6 +14,7 @@ func main() { mux.Handle("GET /toggle-multiple-forms/", http.StripPrefix("/toggle-multiple-forms", http.FileServer(http.Dir("toggle-multiple-forms")))) mux.Handle("GET /character-count/", http.StripPrefix("/character-count", http.FileServer(http.Dir("character-count")))) mux.Handle("GET /character-word-count/", http.StripPrefix("/character-word-count", http.FileServer(http.Dir("character-word-count")))) + mux.Handle("GET /random-ron/", http.StripPrefix("/random-ron", http.FileServer(http.Dir("random-ron")))) log.Println("Start the web server...") err := http.ListenAndServe(":8080", mux) diff --git a/js-essentials/random-ron/README.md b/js-essentials/random-ron/README.md new file mode 100644 index 0000000..8e2dfb1 --- /dev/null +++ b/js-essentials/random-ron/README.md @@ -0,0 +1,9 @@ +# Character count + +Display the number of characters a user has typed into a textarea +element in real time as they type. + +# Reference + +* https://leanwebclub.com/learn/js-essentials/project-character-count/ + diff --git a/js-essentials/random-ron/index.html b/js-essentials/random-ron/index.html new file mode 100644 index 0000000..09b1281 --- /dev/null +++ b/js-essentials/random-ron/index.html @@ -0,0 +1,19 @@ + + +
+ + + ++ +
+ + + + + diff --git a/js-essentials/random-ron/script.js b/js-essentials/random-ron/script.js new file mode 100644 index 0000000..78ff925 --- /dev/null +++ b/js-essentials/random-ron/script.js @@ -0,0 +1,30 @@ +let blockquote = document.querySelector('blockquote'); +let button = document.querySelector('button#get-quote'); + +getQuote(); + +function getQuote () { + blockquote.textContent = 'Getting a fresh quote...'; + + fetch('https://ron-swanson-quotes.herokuapp.com/v2/quotes').then(function (response) { + if (response.ok) { + return response.json(); + } + + throw response.status; + + }).then(function (data) { + blockquote.innerText = data[0]; + }).catch(function (error) { + console.warn(error); + }); +} + +button.addEventListener('click', function (event) { + getQuote(); +}); + + + + +