Code Snippets

JavaScript Training for Beginners

How to Make an AJAX Request with the fetch() Method

I'm working on a new project in my JavaScript course building a "Dog Therapy" page where you click on a button and get a new image from https://dog.ceo/dog-api/ Here is a snippet of the project where we answer the question: "How do we make an AJAX request from our program to get access to...

READ MORE

Anatomy of a for loop

There are a lot of ways in vanilla JS to loop over things such as an array or a NodeList. In this post we are going to look at one of the first approaches to this called a for loop. Let's look at the anatomy of a for loop. How the for loop works for (initialization; condition;...

READ MORE

Randomly Sort an Array

If you ever need to randomly sort an array of items in JavaScript, here’s a simple function to help you do so: var shuffleArray = function (array) { // Create a copy of the array so that we don't shuffle the original one var arrayCopy = array.slice(0); // Shuffle the array return...

READ MORE

Code Notes - Operands

Definition: “Operators are used to assign values, compare values, perform arithmetic operations and more. Operators allow programmers to create a single value from one or more values.” Binary Operators: Definition: Requires two operands, one before the operator and one after the...

READ MORE

Code Notes - JavaScript Strings

Definition: "Strings are a data type used to represent text and are wrapped in either a single or double quotes." "A list of characters surrounded by quotes, used to represent text in computer programs." "Strings in JavaScript (as in most programming languages) are just sequences of...

READ MORE

Code Notes - JavaScript Variables

Variable Definition: “JavaScript variables are containers for storing data values. Variables are named containers that you can place data in and then refer to the data by naming the container.” "A variable is a named value in your program. Whenever you use the name in the program, it's...

READ MORE