Last active
January 30, 2022 23:05
-
-
Save mosherbrian/48cd26079264dc96c0ef9ec8555a4893 to your computer and use it in GitHub Desktop.
Gist for Vanilla JS Academy Week 3 projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Random Ron</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<style type="text/css"> | |
body { | |
margin: 0 auto; | |
max-width: 40em; | |
width: 88%; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Random Ron</h1> | |
<blockquote aria-live="polite"><em>Getting a fresh quote...</em></blockquote> | |
<p> | |
<button id="get-quote">More Ron</button> | |
</p> | |
<script> | |
"use strict;" | |
let btn = document.querySelector("button"); | |
let quoteText = document.querySelector("blockquote"); | |
let quotes = []; | |
async function GetQuote() { | |
try | |
{ | |
let response = await fetch("https://ron-swanson-quotes.herokuapp.com/v2/quotes"); | |
if (!response.ok) | |
throw "Something went wrong."; | |
return response.json(); | |
} | |
catch (error) | |
{ | |
return "[Something went wrong, sorry!] I have a joke for you... The government in this town is excellent, and uses your tax dollars efficiently."; | |
} | |
} | |
function DeduplicateArray(quote) | |
{ | |
if (quotes.includes(quote)) | |
return ""; | |
if (quotes.length > 49) | |
quotes.shift(); | |
quotes.push(quote); | |
return quote; | |
} | |
async function SetQuote() | |
{ | |
while ( !(quoteText.textContent = DeduplicateArray( await GetQuote() ) ) ); // semi-colon | |
} | |
btn.addEventListener("click", SetQuote); | |
SetQuote(); | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Character & Word Count</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<style type="text/css"> | |
body { | |
margin: 0 auto; | |
max-width: 40em; | |
width: 88%; | |
} | |
label { | |
display: block; | |
width: 100%; | |
} | |
textarea { | |
min-height: 24em; | |
width: 100%; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>VanillaJS Academy - Week 3 Projects</h1> | |
<script> | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment