VICO 3420/5900

JavaScript + Data

Exercise 1: Functions and For Loops

w3schools: Functions w3schools: For Loops Download: Exercise 1 files

Functions

Functions are the bread and butter of JavaScript programming. A function is a block of code that will perform a particular task. A function is executed when "something" calls it.

The concept of wrapping a piece of code in a value has many uses. It gives us a way to structure larger programs, to reduce repetition, to associate names with subprograms, and to isolate these subprograms from each other.

// simple function
let simple = function () {
  console.log('It worked!');
}

// same as...
function simple() {
  console.log('It worked!');
}

For Loops

For Loops can execute a block of code a number of times. They are a great way to work with arrays of data!

// simple 'for loop' function
let looper = function () {
  for (let i = 0; i < 10; i++) {
    console.log(i);
  }
};
Dynamic HTML will go here: