Created
April 24, 2020 15:28
-
-
Save diekmann/f7f27b4c558c5f8565bf235a535e729a to your computer and use it in GitHub Desktop.
The worst web-technology FizzBuzz? The worst web-technology FizzBuzz so far!
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
<html> | |
<head> | |
<style> | |
/* The printing of Fizz or Buzz instead of numbers is just style. Moving the logic to CSS.*/ | |
p:nth-child(3n){ | |
visibility: hidden; | |
} | |
p:nth-child(3n)::before{ | |
visibility: visible; | |
font-size: medium; | |
content: "Fizz"; | |
} | |
p:nth-child(5n){ | |
visibility: hidden; | |
font-size:0; | |
} | |
p:nth-child(5n)::after{ | |
visibility: visible; | |
font-size: medium; | |
content: "Buzz"; | |
} | |
</style> | |
</head> | |
<body> | |
<p>1</p> | |
<script> | |
const last = (t) => Array.from(document.querySelectorAll(t)).pop(); | |
const append = (type, txt) => last('body') | |
.appendChild(document.createElement(type)) | |
.appendChild(document.createTextNode(txt)); | |
/* Everything needs an event queue.*/ | |
const queue = []; | |
const enqueue = queue.unshift.bind(queue); | |
const dequeue = queue.pop.bind(queue); | |
/* Such an async main event processing loop*/ | |
((f) => f(f))((f) => setTimeout(() => dequeue()().then(f(f)), 200)); | |
</script> | |
<script> | |
/* Use the DOM! */ | |
enqueue(async () => { | |
append('p', Number(last('p').textContent)+1); | |
append('script', last('script').textContent); | |
}); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment