Reflections Front End Web Development – Javascript Continued – Lesson 13

I have taken a few moments to write down my thoughts about Lesson 13 on Javascript Loops to answer the following questions:

  • What new skills have I learned?
  • What has been easy?
  • What has been difficult?
  • How have I used the problem solving strategies from the first project to overcome challenges so far?

Here I have a confession to make. I already have a Masters of Computer Science from Boston University (just graduated on December 2017), with a concentration in Project Management. As a prerequisite for graduation, I had to take some developer courses, alongside coursework on project management, that included Java. Even though Java (an objected-oriented programming language) is not the same as Javascript (an interpreted programming language), the concepts and syntax are similar enough that I can leverage what I have learned in the past, and apply here to my Udacity lessons.

In other words, I’ve already done my head bashing with Conditionals and Loops, sometime in the past.  Loops and Conditionals, when I first encountered them, were one of the most difficult programming concepts to master.  However, with perseverance, and some help from my fellow classmates, I was able to learn and apply these concepts in my basic code.  So when I came across loops here again, I just fired up my old Eclipse IDE, and reviewed that basic code I had written years ago.

Java Eclipse

Therefore, overall, I found this lesson to be moderately challenging (especially given the many provided online resources, and my prior experience with Java), and did not encounter any significant difficulties. Here we learned about the use of Loops in Javascript.  This included:

  • While Loops
  • For Loops
  • Nested Loops
  • Increment and Decrement

Collected Lesson 13 Quizzes on Loops in

Also refer to my notes on Loops below:

While Loops

Loops repeat an action some number of times.  The three main pieces of information that any loop should have are:

(1) When to start:  The code that sets up the loop — defining the starting value of a variable for instance.
(2) When to stop: The logical condition to test whether the loop should continue.
(3) How to get to the next item: The incrementing or decrementing step — for example, x = x * 3 or x = x – 1

Here’s a basic while loop example that includes all three parts:
var start = 0; // when to start
while (start < 10) { // when to stop
start = start + 2; // how to get to the next item

For Loops

The for loop explicitly forces you to define the start point, stop point, and each step of the loop. In fact, you’ll get an Uncaught SyntaxError: Unexpected token ) if you leave out any of the three required pieces:
for ( start; stop; step ) {
// do this thing

Here’s an example of a for loop that prints out the values from 0 to 5. Note the semicolons separating the different statements of the for loop: var i = 0; i < 6; i = i + 1:
for (var i = 0; i < 6; i = i + 1) {
console.log(“Printing out i = ” + i);

Nested Loops

You can also nest loops inside of each other:
for (var x = 0; x < 5; x = x + 1) {
for (var y = 0; y < 3; y = y + 1) {
console.log(x + “,” + y);

Increment and Decrement

Summary of operators that increment and decrement:
x++ or ++x // same as x = x + 1
x– or –x // same as x = x – 1
x += 3 // same as x = x + 3
x -= 6 // same as x = x – 6
x *= 2 // same as x = x * 2
x /= 5 // same as x = x / 5

Happy Coding and Blogging!



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s