Open suuuth opened 6 years ago
Wow, this is fantastic, @suuuth! I love the rotation of images on the cuteness page. 😍
Everything looks and works great. I have one tip to improve your random joke selection.
I like how you organized your jokes into an object. It looks like you found a way to use that data structure and pick one at random using an if
/else if
block. There's an even shorter way you can pull this off — and it doesn't require any conditional logic.
Consider this:
var jokeKeys = Object.keys(jokes)
thisjoke = jokeKeys[Math.floor(Math.random() * jokeKeys.length)]
setup = jokes[thisjoke].setup
punchline = jokes[thisjoke].punchline
This puts the joke keys in an array and uses some math to pick one at random, then uses the random key to get the setup and punchline. It's way less code and doesn't need to be changed if you add or remove entries from jokes
.
Try it out and let me know what you think!
After you’ve made your changes and pushed them to GitHub and your hosted site, give it a once-over to make sure it looks right, then comment back here and I’ll take another look.
Thanks! 🤖
This is clever. I patched it and it should be updated now. Take another look when you get a chance @egillespie thank you
I'm glad you like it! Clever solutions come from laziness and not wanting to maintain code unnecessarily. 😅
Your project is fantastic, very nicely done! 🤘 :shipit:
Build a simple web server that handles any URL
@egillespie Can you take a look at this? It's hosted here and meets the following criteria:
h1
element (though for this project, it doesn't have to be a complete HTML page)/
, they see a greeting/random-joke
, they see one of at least three knock-knock jokes (Math.random()
may be useful 😉)/cuteness
, they see a picture of a cute animal (I'm sure you can find one on the Internet 😛)/
) contains a link to it