Member-only story
JavaScript Functions For Dummies (Me): Part 1
Drilling The Basics: An Intro To .ceil(), .reverse(), .split(), and .join()
Each morning before getting into the thick of class we are given coding challenges. I really enjoy these as a way to prime our minds for the day ahead.
As I do these I’m realizing 1) how much I don’t know, and 2) that there are certain concepts that keep resurfacing, and that it might be helpful (to me) to write out my thought process — and the solutions — as a way to drill them in.
Someone recently introduced me to CodeFights, which I’m very thankful for. The below questions are from their JavaScript Intro: “The Journey Begins”.
Using JavaScript to Return the Century a Given Year Is In
The Question
// "Given a year, return the century it is in. The first century spans from the year 1 up to and including the year 100, the second - from the year 101 up to and including the year 200, etc."
My Thought Process
I first thought to use the .round()
method, but after trying a few iterations of this I realized it was rounding down when, for example, the year was between 1901 and 1949 because in dividing it by 100, the…