Created
December 13, 2022 03:43
-
-
Save nanxstats/3fef4e38d736d491433be0e843d5616b to your computer and use it in GitHub Desktop.
Click to change to a random superlative using JavaScript
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
--- | |
title: "Click to change to a random superlative" | |
output: html_document | |
--- | |
From <https://www.garrickadenbuie.com/blog/countdown-v0.4.0/>. | |
I'm <span class="superlative">overjoyed</span> to announce that... | |
```{css} | |
.superlative { | |
border-bottom: 1px dashed; | |
cursor: pointer; | |
} | |
.superlative:hover { | |
color: #fb7e8c; | |
} | |
``` | |
```{js} | |
document.addEventListener("DOMContentLoaded", function () { | |
document | |
.querySelector(".superlative") | |
.addEventListener("click", function (ev) { | |
const superlatives = [ | |
"delighted", | |
"charmed", | |
"elated", | |
"excited", | |
"pleased", | |
"thrilled", | |
"chuffed", | |
"tickled pink", | |
"overjoyed", | |
"ecstatic", | |
"stoked", | |
"proud", | |
"fired up", | |
]; | |
const el = ev.target; | |
const idx = Math.floor(Math.random() * superlatives.length); | |
el.innerText = superlatives[idx]; | |
}); | |
}); | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment