First step was to head back over to freeCodeCamp which I started a few months back but then backed off due to how difficult it was. The experience points remained in tact on my account but I knew I had to go back to the beginning in order to gain an understanding of how JS works. The difference between then and now is that instead of powering through each exercise, I’d tinker with the solution. Switching up the test argument so the output produced a different result and refactoring the code to come up with a more efficient solution soon enough became a common practice.
Then it hit me. The very thing that eventually happens to all novice developers. It finally clicked!
Through learning JS it helped me better understand Ruby. Despite subtle and not-so-subtle differences, they have similarities. For example one of the coding challenges from FCC was to create a program that would convert a temperature degree from celsius to fahrenheit. Here was my solution written in JS.
Now here is my solution written in Ruby.
Despite the differences in syntax, they couldn’t be any more similar. “function” in JS is the equivalent to “def” in Ruby. They’re both used to establish the function of that block of code that will eventually be called upon based on the argument(s).
The formula to convert celsius to fahrenheit is similar in both cases since both JS and Ruby follow the PEMDAS rule to calculate equations. The difference being that in JS you have to add “var” in order for the function to be executed, call the method within the function, and be mindful of bracket and semi-colon placement. Ruby simply requires you end each function with “end”.
Ever since this exercise I make it a point to not only find the solutions but also to translate it from JS to Ruby and it’s helped me learn and understand both languages (and by extension programming in general). What was frustrating at first is now starting to become fun!