• Basics,  JavaScript/Ajax

    JavaScript Basics Part 7: Loops

    Loops are used to execute the same statement of code a set number of times, which can be hardcoded or based on variable. Loops are very common within programming, as they solve the problem of having to write more code to do the same thing multiple times. There are two different types of loops: for and while loops, which both perform looping tasks but in different ways, suitable for different problems. for The for loop will run for a set number of times then stop. [js] var I = 0; for(I = 0; I < 5; i++) { Alert("My number"+ I); } [/js] If you had to write out a…

  • Basics,  JavaScript/Ajax

    JavaScript Basics Part 6: Conditionals

    Logic is a part of our everyday lives – it’s a very familiar concept, therefore one of the easiest to understand. We are faced with questions all the time, with the “If” question being the most common. If I go to sleep early, I will be able to get up early. If I take this job, I will make more money. If I go to school, I will learn JavaScript. Using JavaScript, you can answer all of these questions using conditional statements. Conditional statements allow you to setup the question or logic within your script, and if it is a true statement, then actions can be taken which are defined…

  • Basics,  JavaScript/Ajax

    JavaScript Basics Part 5: Arrays

    An array is a variable which can store many values inside it. A variable can only store one value. Those values can be accessed at any time using the array’s index. The values stored within the array are called the members. Creating an array To create an array, declare a variable to hold values of the array, and declare the new Array object. [js] var navArray = new Array(); [/js] Alternately, you can also use a shorthand version, which will achieve the same outcome, where you wont have to declare the new array object. [js] var navArray = []; [/js] Similar to variables, you can setup a new array and…

  • Basics,  JavaScript/Ajax

    JavaScript Basics Part 4: Variables

    Variables offer a way to store values of strings, numbers, and boolean data types, as well as being able to reuse at any point within your script. Declaring or creating variables is a common practice when writing any sort of script or program. I will setup variables to store different bits of data that I want to access multiple times. They allow you to create cleaner, more readable, and more organized code. There are two ways to use variables, the first is by just declaring a variable as show below: [js] var numClicks; [/js] You can also declare a variable and set a value to it. The “var” syntax is…

  • Basics,  JavaScript/Ajax

    JavaScript Basics Part 3: Strings

    A string is anything enclosed within quote marks – it can be made up of letters, numbers, and/or symbols. Strings will work with either single or double quotes. [js] “hello world”; ‘I have 5 pears’; [/js] When creating strings, there are often times when you will want to join one or more strings together. This is call concatenation, and is used by adding a “+” (plus sign) in between the strings you want to join together. [js] “hello” + “world”; [/js] Jake Rutterhttp://www.onerutter.com

  • Basics,  JavaScript/Ajax

    JavaScript Basics Part 2: Comments

    JavaScript comments are a way to keep your code clean and easy to read. Comments cannot be rendered because the browsers skip them. Most web designers are probably familiar with HTML comments, which are similar to JavaScript comments with the exception of the syntax. There are two types of comments that you can use in JavaScript: single and multiple line comments. Single line comments are created using two slashes “//” in front of the line of text. Multiple line comment blocks are created by wrapping the text with a slash and an asterisk “/*” and closing the comment block by adding an asterisk and a slash “*/”. In CSS, comments…

  • Basics

    JavaScript Basics Part 1: Statements

    The basic components of JavaScript programs are statements, variables, and types of data. A JavaScript statement is the most basic piece of JavaScript – which will represent a single action or step in the script that you are building. Many statements will represent a script, and they will always run from top to bottom, similar to how you read a book. In the following example, there are two statements. The first will write the line ‘hello world, this is the edge’ to the document. The second statement will show a JavaScript alert to the user that says ‘say hello to the world’. You will notice at the end of each…