Aaron is a Software Developer experienced in web development and business-process management applications. He also enjoys soccer, craft beer, and cheering for "next season" as a Cleveland Browns fan.
Mind blown. Thank you all! I'm just now getting into ES6 and shorthand functions etc. I just love how there are ways to do in 10 lines what I did in ~50-60 lines. Incredible.
I'll be referencing this when I update the code in the next few weeks. Thank you both!
Junior Developer at Interplay Learning - Feel free to contact me via LinkedIn or connect on Github, I am always happy to chat with folks from this community!
Great job! It looks like the other commenters beat me to it as far as suggestions since I was also thinking of ways to have code that is more DRY (Don't Repeat Yourself). Overall, I love seeing you go from idea to useful app! If you do end up writing a function that lets you pass the sides as an argument, you could add a feature so that the user can enter a custom sided die. Good luck!
We're a place where coders share, stay up-to-date and grow their careers.
You repeat yourself a lot. :)
The following technique may help avoid that.
Here d is a function which generates parameterized functions by using lexical closure.
You don't need to have a function that returns another function. You can simplify it to this:
And use it with this:
Mind blown. Thank you all! I'm just now getting into ES6 and shorthand functions etc. I just love how there are ways to do in 10 lines what I did in ~50-60 lines. Incredible.
I'll be referencing this when I update the code in the next few weeks. Thank you both!
That's true, but his code wants to call functions directly.
Also, why are you adding 1 and then flooring?
I am adding one because
Math.random()returns a float between 0 and 1, but it never includes 1, so you could never get 20 without adding 1.Why not use Math.ceil?
Great job! It looks like the other commenters beat me to it as far as suggestions since I was also thinking of ways to have code that is more DRY (Don't Repeat Yourself). Overall, I love seeing you go from idea to useful app! If you do end up writing a function that lets you pass the sides as an argument, you could add a feature so that the user can enter a custom sided die. Good luck!