tech four

how does javascript compare to html and css?

HTML is the basis of a website, putting different elements in sections. This makes sure the browser knows a paragraph is a paragraph, a title is a title, a picture is a picture etc. CSS stylises these different sections and informs the browser which font, color, margins etc. apply to which section(s).*
JavaScript is what makes the site more interactive and user-driven. For example, allowing them to type in a search, leaving their details, a rotatable picture, or an interactive picture side-bar.

control flow

Control Flow is the order in which the computer follows instructions. We read a book from the beginning to the end, similar to how the computer reads instructions from first to last. However, there are exceptions to this rule. The if/else rule is like reading a Goosebumps book. In these stories, as you read, you would be presented with options.
a) If you open the door, turn to page 48.
b) If you peep through the keyhole, turn to page 30.
c) If you walk past the door, carry on reading.
A computer might read this as:

What do you do?
If a)
- Go to page 48.
If b)
- Go to page 30.
if neither a) or b)
- Go to next page.

If none of these conditions are met, the computer will "loop" the instructions until one of them is.

arrays and object literals

Arrays and Object Literals are both useful ways to store data. Arrays are held within square brackets [], and contain data that is indexed from 0 - n (n being the last piece of data in the array). Arrays can have mulitple types, and many pieces (even paired) of data, but they must be stored in an array within the main array. To access data in an array, you must call the number that that array has been assigned. As opposed to starting at 1, arrays start counting at 0.
Array 1 is assigned to "0"
Array 2 is assigned to "1"
Array 3 is assigned to "2"
and so on.

Object Literals are held within curly brackets {} and contain data that is sorted into pairs: each property is assigned a value. Object literals are not assigned numbered values, so you cannot call object.literal[1], like you can with an array. Instead you can call a property and it will return the value of that property to you. Object Literals also allow several pieces of data to be linked to one thing. This is possible in arrays too, but this requires having a sub-array (possibly multiple sub-arrays) within an array. This can get very confusing when you are calling an array , or even when you are assigning numbers to the data.

Object Literals are much easier to format and read, and are great for viewing seperate pieces of data without going back-and-forth between number and what is assigned to that number.

functions

Functions are sets of code that perform a certain action. Instead of having to repeat ourselves when a certain action needs to be done, we can call the function and it will do everything within that set of code. This is fantastic and saves a lot of time as we don't need to repeat our instructions to the computer every time, we can tell it to perform the instructions in a function.

* Click: for a more relatable analogy