Skip to content

Instantly share code, notes, and snippets.

@nanxstats
Created December 13, 2022 03:43
Show Gist options
  • Save nanxstats/3fef4e38d736d491433be0e843d5616b to your computer and use it in GitHub Desktop.
Save nanxstats/3fef4e38d736d491433be0e843d5616b to your computer and use it in GitHub Desktop.
Click to change to a random superlative using JavaScript
---
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