Created
January 11, 2022 16:13
-
-
Save draffauf/31b104e49c1d6487f24fd772ca9dd7b3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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