Skip to content

Instantly share code, notes, and snippets.

@draffauf
Created January 11, 2022 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save draffauf/31b104e49c1d6487f24fd772ca9dd7b3 to your computer and use it in GitHub Desktop.
Save draffauf/31b104e49c1d6487f24fd772ca9dd7b3 to your computer and use it in GitHub Desktop.
// Instructions: at codesandbox.io, create a Vanilla JS sandbox,
// and paste this file into index.js
import './styles.css';
const Languages = [
'JavaScript',
'TypeScript',
'Python',
'Ruby',
'C',
'C++'
];
const Expressions = ['😍', '🤣', '💀'];
const Adjectives = [
'Awesome',
'The Worst',
'Optimized',
'Amazing',
];
const zeroBasedRandomizer = (max) => Math.floor(Math.random() * max)
const itemFromList = (
list,
chooser = zeroBasedRandomizer
) => {
const index = chooser(list.length);
const item = list[index];
return item;
}
const topicGenerator = (
languages = Languages,
expressions = Expressions,
adjectives = Adjectives
) => {
const adjective = itemFromList(adjectives);
const language = itemFromList(languages);
const expression = itemFromList(expressions);
return `${adjective} ${language} ${expression}`;
}
const html = `<h1>${topicGenerator()}</h1>`;
// Find HTML element "app" and set the html;
document.getElementById("app").innerHTML = html;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment