Add "Random Ron" project
This commit is contained in:
parent
08486cec5e
commit
2745644f30
4 changed files with 59 additions and 0 deletions
|
@ -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 /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-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 /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...")
|
log.Println("Start the web server...")
|
||||||
err := http.ListenAndServe(":8080", mux)
|
err := http.ListenAndServe(":8080", mux)
|
||||||
|
|
9
js-essentials/random-ron/README.md
Normal file
9
js-essentials/random-ron/README.md
Normal file
|
@ -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/
|
||||||
|
|
19
js-essentials/random-ron/index.html
Normal file
19
js-essentials/random-ron/index.html
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en" data-bs-theme="dark">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css">
|
||||||
|
<title>Random Ron</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Random Ron</h1>
|
||||||
|
<blockquote aria-live="polite"></blockquote>
|
||||||
|
<p>
|
||||||
|
<button id="get-quote">More Ron</button>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
<script src="script.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
30
js-essentials/random-ron/script.js
Normal file
30
js-essentials/random-ron/script.js
Normal file
|
@ -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();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue