Using JavaScript & Arrays for Sliders

Often, you will have data stored in an array that you will want to allow the user to “slide” through. This requires HTML, CSS and JavaScript all working together. Here’s the working example And the code is located in CodeAnywhere in labcatscoding/s/app/js.php Let’s walk through it. Set it up Initialize an empty array in order…

Read More

Exercise: Drawing Lines

Let’s make a new page to play with lines some. Create a file called lines.html. Add a blue line that goes from the top right corner to the bottom left corner. Add a red line that is 5 pixels wide and goes across the canvas horizontally at the midpoint. Add a green line that cuts…

Read More

Homework: JavaScript Form Validation

Homework – Forms & JavaScript Validation Add some JavaScript to the form you created in form1.php. Make sure their first name is not Scum If there last name is longer then 30 characters – tell them it is invalid and must be entered again.

Read More

External Scripts and Functions

Pulled from “How to Use JavaScript” …edit! Using the External Method Why? Because the code is easier to read and to maintain and can be used by multiple web pages. How? Simply link to an external file via a src attribute in the head section. Create your HTML file. Add this line into your <head>…

Read More

Returning Values From a Function

One of the most valuable things a function does is to return a value to the program that called it.  That value can be a single value like a number or a string – or a boolean value to determine if a certain condition is met.  Functions can also return arrays which contains lots of…

Read More

Review: using external script

Pulled from “How to Use JavaScript” …edit! Using the External Method Why? Because the code is easier to read and to maintain and can be used by multiple web pages. How? Simply link to an external file via a src attribute in the head section. Create your HTML file. Add this line into your <head>…

Read More

Passing Values to a Function

This allows us to pass information for the function to use. First, let’s learn how you do it and then we will learn about how and why it is useful. You pass data to functions through parameters. A function can have 0, 1 or multiple parameters passed to it You have already seen what zero…

Read More

Loops and Arrays in JavaScript

You can use both for and while loops to easily access each element in an array. Let’s take a look at each one. Arrays and for loops for loops are very useful with arrays as you can easily loop through the array. var insects= [“ant”, “ladybird”, “bee”, “grasshopper”]; var len = insects.length; for (var i…

Read More

Homework: Basic Loops

Exercise Create a codepen called loops and add these features: Ask the user for a number between 5 and 15. Create a while loop to show an alert for each value up to that number. Do a countdown loop for the same number the user supplied above – use the alert() statement to tell the…

Read More

while Loops in JavaScript

while Loops A while loop repeats the block of code as long as the condition is true. A condition is basically a boolean statement – is the variable i less than 5? Has the user provided input that says tells you to stop? The basic syntax is this: while (condition) { code block to be…

Read More