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 MoreReview: 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 MorePassing 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 MoreLoops 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 MoreHomework: SELECT Variations
Homework Go into phpMyAdmin! Open up the state table up and look at the structure and the data. Then go to the SQL tab while that table is selected. Use this as your work space to answer the questions in the quiz!
Read MoreSpecify Number of Records
SELECT TOP/LIMIT/ROWNUM This allows you to specify the number of records to return. Note: that the exact syntax varies depending on the database syntax you are using. We are using MySQL so it would be LIMIT. But we’ll show the basic syntax for all three major varieties first. MySQL SELECT column1, column2,… FROM table_name WHERE…
Read MoreHomework: 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 MoreSorting by Multiple Columns
Sometimes you want to be able to sort records by multiple column. In MySQL, you can’t really sort equally but you can sort first by one field and then within that field, sort by another. Let’s take a look at an example. If you wanted to see all students sorted by which language they were…
Read MoreMultiple Conditions in the WHERE Clause
Sometimes you want to look for two conditions – all students who take Chinese and are 16 years old. How do you do this? With the help of the AND, OR and NOT operators. Let’s take a look at what each operator does: AND: displays a record only if meets ALL the conditions OR: displays…
Read Morewhile 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