Learning Challenge for September: JavaScript - Day 3

I'm working through the book Eloquent JavaScript from cover-to-cover. Part of this is baking in the discipline to actually read though the book and not let my experience with other languages overshadow the JavaScript experience. I made it through Chapter 2: Program Structure and did the exercises near the back. What's nice about Eloquent JavaScript is there's worked solutions for the exercises in each chapter. What's interesting is how different our solutions were for each of the questions. For the "FizzBuzz" solution I decided to use a switch / case statement, which showed me just how screwball JavaScript's switch / case statements are:

for (let i = 1; i <= 100; i++) {
    switch (true){
        case (i % 3 === 0) && (i % 5 === 0):
            console.log("FizzBuzz");
            break;
        case (i % 3 === 0):
            console.log("Fizz");
            break;
        case (i % 5 === 0):
            console.log("Buzz");
            break;
        default:
            console.log(i);
            break;
    }
}

Initially I had it as switch(i) but that didn't work at all. I had to look on StackOverflow to find the right answer.

This is also about carving out learning time. I'm working on trying to get at least 30 minutes per day doing some form of learning exercise. That might not seem like a lot, but keeping it consistent will be key for my learning challenge (especially as I decide to tackle more difficult projects).


links

social