suuuth / MI-449-SS18-740-js-server-intro-jtrO3q

0 stars 0 forks source link

Project Feedback #1

Open suuuth opened 6 years ago

suuuth commented 6 years ago

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:

egillespie commented 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.

A shorter way to pick a random joke

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! 🤖

suuuth commented 6 years ago

This is clever. I patched it and it should be updated now. Take another look when you get a chance @egillespie thank you

egillespie commented 6 years ago

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: