codeburst

Bursts of code to power through your day. Web Development articles, tutorials, and news.

Follow publication

Member-only story

Project Euler Problem 2 Solved with Javascript

Jared Nutt
codeburst
Published in
4 min readJan 27, 2020

--

Getting all the even Fibonacci numbers

Welcome to Round Two of Project Euler! This time we’re heading into the land of state management and that guy you’ve probably heard about: Fibonacci! I’m excited, are you excited?

Check out the solution for Problem 1 here:

Video Version

If you like to watch rather than read, check out the video that accompanies this article. If not, keep reading!

Problem 2: Even Fibonacci Numbers

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, …

Problem Statement

By considering the terms in the Fibonacci sequence that do not exceed the nth term, find the sum of the even-valued terms.

Solution

Breakdown of the Problem

Fibonacci sequence

It’s stated in the problem, however, let’s discuss what a Fibonacci sequence is a little bit and why it’s important.

The next number is found by adding up the two numbers before it.

When we do this, it creates an interesting spiral, which is found in myriad places in nature.

We could probably talk all day about Fibonacci, but let’s get back to code.

Steps

--

--

Published in codeburst

Bursts of code to power through your day. Web Development articles, tutorials, and news.

Written by Jared Nutt

Freelance web developer living in Los Angeles. I write articles I wish I had when I was learning — mostly about Javascript and web development.

Responses (1)

Write a response