Title photo
frugal technology, simple living and guerrilla large-appliance repair
Sun, 18 Jun 2017

Eloquent Javascript, Chapter 3 (Functions) -- what the hell?

I read Chapter 3 of Eloquent Javascript some time ago, and it's a difficult one. It introduces the concept of functions. Quickly introduced are: Parameters and Scopes, Nested Scopes, Closure and Recursion.

It is too much, too fast with too few examples. I was able to do the first exercise, Minimum, but got lost in the second, Recursion.

Here is my solution for Minimum:

#!/usr/bin/env node
/* Eloquent Javascript, Chapter 3, Page 56, Exercises 
Create a function to find the minimum of two arguments

By Steven Rosenberg, 6/17/2017 */

function smallest(first_number, second_number) {
    if (first_number < second_number)
        return first_number;
    else if (second_number < first_number)
        return second_number;
    else
        console.log("They are equal")
}

// Output will be the smallest of these two numbers
console.log(smallest(100, 2));

Expressing this as a function doesn't really do much. The program could just as easily have been written in a straight "procedural" format. But it's a function, and it works.

The second problem on recursion stumped me. I'm pretty sure I can figure it out, but I need more time to think (and look up more on recursion).

Wed, 29 Mar 2017

Eloquent JavaScript - Chapter 2 exercises - Fizz Buzz

I'm not saying I will make it through all 22 chapters of "Eloquent JavaScript," by Marijn Haverbeke, but enough people I respect have recommended the book that I'm doing my best to absorb what I can from it.

To that end, I am doing the exercises in the back of each chapter, and I plan on presenting my solutions here.

This entry also serves as a test of the Highlight.js JavaScript library, which I just added to this Ode site for syntax highlighting of code. I'm using the zenburn CSS.

Back to "Eloquent JavaScript." If you don't want any hints, don't go past the blog index. I will only start showing my code after the "read more" portion of each entry.

Before maybe a year ago, I'd never heard of Fizz Buzz, where you write a program that outputs the words Fizz, Buzz or Fizz Buzz depending on whether a number is divisible by 3, by 5 (and not 3) or by 5 and 3.

Fizz Buzz is supposedly used as a programming test in hiring. I was surprised when it was given as the second exercise in Chapter 2

Read the rest of this post