top of page

JavaScript Projects

JavaScript (JS) is a dynamic and highly interactive computer programming language used by web developers. Web browsers on our computers include a JavaScript interpreter. That means that the JavaScript program is read and displayed at the client-side, or directly by the person connecting to the website. A script is nothing more than a set of instructions that the computer is ordered to do.

 

JavaScript has also become common in server-side programming, game development (think of the Cool Math Games website) and the creation of many more applications. 

Understanding JavaScript is important in the Web II class, and will open the doors to many exciting work opportunities.

Hello Bradley Tech!

My first little JavaScript project!

Loops 

Keyword: Loop. Programming structures designed to repeat a section of code as many times as necessary in order to meet a programming goal. We use loops to simplify our coding, and will result in a block of instructions to repeat itself until a certain condition is met.

My project on the right shows a FOR LOOP used to iterate over the items in an array and do something with each of them — a very common pattern in JavaScript.

This little program will list my favorite Milwaukee Bucks players from an array of names. With each loop, the program will print one of those names and then test the condition if it printed the total number of names found in that array. If the number printed is less than the number of names in my array, the condition is true and the loop will continue and another name is printed. The loop will stop when the total number of names printed is equal to the number of names in the array and the condition becomes false.

 

First, our program needs an iterator. Keyword: Iterator.

An iterator is an object that allows the execution of the next sequence of our written program.

For easy identification we identify the iterator as i. We also assign it an initial  value of 0.

Loops create iteration. Keyword: Iteration. Iteration is

the repetition of programming commands.

 

We want our program to LOOP UNTIL the iterator is no longer smaller than the length of our Bucks array of team members.

While i < bucks.length is true, the program loop will continue to run. With each cycle we see our var i will be increased by 1 by the iteration specified of i++1

 

When i becomes equal to bucks.length (the number of names on our Bucks roster) our loop will stop, and the browser will move on to the next bit of code below the loop.

 

<html>
<body>
<h2>Standard FOR Loop: Very Popular!</h2>

<h3>Members of the Milwaukee Bucks are:</h3>

<p id="forLoop"></p>

<script>
var bucks = ['Giannis Antetokounmpo', 'Jabari Parker', 'Eric Bledsoe', 'Khris Middleton', 'Brandon Jennings', 'Malcolm Brogdon'];
var i, len, text;
for (i = 0, len = bucks.length, text = ""; i < len; i++) {
    text += bucks[i] + "<br>";
}

document.getElementById("forLoop").innerHTML = text;
</script>

</body>
</html>

bottom of page