In this topic we are going to cover the basics and later on we will dive deeper.
Let’s get started!
The MDN tutorial isn’t bad either, so check it out if you need another take on the subject.
Watch this short introductory video on Arrays by Code.org:
Duration: 4 minutes
Some things to be aware of while going through the tutorial:
var x = cars.length; var y = cars.sort();
let carsLength = cars.length; let sortedCars = cars.sort();
The same best practices mentioned above (avoid
var, use meaningful variable names) apply to this tutorial also.
NOTES: If you are unaware of the following command mentioned in this tutorial, here’s a short explanation of what it does:
document.getElementById("demo").innerHTML = fruits;
This command searches through the document (our HTML page), for an element with id demo and replaces its HTML content with the contents of the fruits variable.
For example, let’s say we have the following HTML content in our document:
<div id="target">Some content here</div>
The following code will replace the current HTML content of this div (Some content here) with <strong>JS rocks!</strong>:
let content = "<strong>JS rocks!</strong>"; document.getElementById("target").innerHTML = content;
Arrays are not only a handy way to store data but also have a set of functions for manipulating that data. These functions are very important and once you start using them you will see that the possibilities of what you can do with them are near endless.
Objectives of these section:
Learn about the forEach Array method
Learn about the filter Array method
Learn about the map Array method
Learn about the sort Array method
Learn about the reduce Array method
Duration: 24 minutes
Part 2of Wes Bos’s array series.
Duration: 8 minutes
Programming languages are very useful for completing repetitive tasks. Fortunately computers are able to solve problems that involve lot of calculations multiple times. Something that will take a human hours to complete, computers can do that in a few seconds. As expected the speed depends on the complexity of the calculation as well as the computer itself. A way to make a computer to do a repetitive task is using a loop.
Read this MDN article: Looping Code. This article is a long one, but make sure you tackle the ‘Active Learning’ sections at the bottom of the page.
Test Driven Development (TDD) refers to the practice of writing automated tests before completing the entire code. In other words, you write some code and then you test it before you write more code.
For example let’s say you want to write a function that multiplies two numbers and returns their product. With the TDD approach you should first write a test that uses that function and gives the expected output. As expected the test will fail before you write the code and when the tests pass then you know that your code works correctly.
In the example above if we had a simple function such as
multiply(2, 2) it wouldn’t be a big deal to check the function ourselves. We would have to run the code over and over again plugging in different numbers until we were sure that it was working. However what would have happened if we had a much more complicated function, for example a function that checks whether or not someone has won a game of tic tac toe
gameWin(["o", null,"x",null,"x",null,"x", "o", "o"])? We would have to play multiple games against ourselves to check that the function is working correctly!
For this reason TDD is a much more productive than writing code without tests. Later in this course we will teach you how to write these tests.
In the exercises we have the tests already written out for you. All you have to do is read the specs and write the code that makes them pass! The very first exercise (
01-helloWorld) is intentionally very simple and walks you through the process of running the tests and making them pass.
Exercism – Uses a neat command-line interface to download and submit exercises and allows you to give and get feedback on your solutions.
CodeWars – A neat gamified system with leveled exercises. As you complete more exercises you level up and access more difficult ones.
HackerRank – Similar in setup to CodeWars, but this site is more focused on interview question type tasks. Some companies even use this site to interview candidates.