Day 12 of 30 of Codewars – Javascript

I’ve challenged myself to 30 days of codewars, one a day, time myself, and learn how I could have done it better.

Today I did: https://www.codewars.com/kata/dont-rely-on-luck/javascript

Time: 8 minutes

What I’ve learnt: It took me about a minute to realize that we need to override a javascript built in function here. And about 7 minutes to realize exactly how to do this. I tried first by recreating the function, but I was getting an error creating a function with the name Math.floor, and then I tried assigning it to a variable with a const, and then realized that won’t work because it has already been created! So I just did Math.floor = and that worked the magic!

Here was my solution:

1
2
3
4
5
var guess = "Sorry. Unlucky this time."

Math.floor = () => {
  return "Sorry. Unlucky this time."
}

 

What I learned from other people’s code:

Well, everyone did this quite similarly, there is not much change you can do. I guess I could have put my arrow function on one line to knock down some of the lines of code, and the return.  I also did not realize that you just had to have a static return, and that it did not need to return that particular string.

And, onto the next!

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright Loving to Code 2025
Tech Nerd theme designed by Siteturner