diff options
Diffstat (limited to 'src/routes/+page.svelte')
-rw-r--r-- | src/routes/+page.svelte | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte new file mode 100644 index 0000000..3519725 --- /dev/null +++ b/src/routes/+page.svelte @@ -0,0 +1,47 @@ +<script lang="ts"> + import { DateTime } from "luxon"; + + const getCurrentYear = () => DateTime.now().year; + const getRelative = (year) => + DateTime.local(year).toRelative({ locale: "en" }); + + let year = $state(getCurrentYear()); + let sqrt = $derived(year ** 0.5); + let isPerfectSquare = $derived(Number.isInteger(sqrt)); + let lastSqrt = $derived(isPerfectSquare ? sqrt - 1 : Math.floor(sqrt)); + let nextSqrt = $derived(isPerfectSquare ? sqrt + 1 : Math.ceil(sqrt)); + let last = $derived(lastSqrt ** 2); + let next = $derived(nextSqrt ** 2); + let nextRelative = $state(getRelative(next)); + + setInterval(() => { + year = getCurrentYear(); + nextRelative = getRelative(next); + }, 500); +</script> + +<div id="container"> + {#if isPerfectSquare} + <div id="answer">Yes.</div> + <strong>{sqrt}</strong><sup>2</sup> = {year}. + {:else} + <div id="answer">No.</div> + {/if} + The last was + <ruby>{last}<rp> (</rp><rt>{lastSqrt}<sup>2</sup></rt><rp>)</rp></ruby>, and + the next is + <ruby>{next}<rp> (</rp><rt>{nextSqrt}<sup>2</sup></rt><rp>)</rp></ruby>, {nextRelative}! +</div> + +<style> + #container { + text-align: center; + font-size: 2rem; + } + #answer { + font-size: 5em; + margin: 0; + font-weight: bold; + font-family: sans-serif; + } +</style> |