Javascript

An analogy to describe JavaScript and its relationship to HTML and CSS.

HTML and CSS documents store the elements/information that is displayed on a website. Javascript is able to manipulate the elements/information from HTML and CSS documents.

If HTML and CSS were a pack of cards, Javascript would be a magician. They’re able to rearrange the deck, select different cards, do crazy shit, etc etc

Explain control flow and loops using an example process from everyday life.

Javascript code is read from top to bottom. Control flow allows you to run different sections of codes at different times. This is done through the use of conditional statements and loops.

There are a few different kinds of loop but the most common is a “for loop”. For loops allow you to repeat a function for a given amount of times. This can be used to iterate through a large array and call a function on the individual pieces of data.

An everyday example of a loop could be putting on your shoes. You put your shoes on the exact same way every single day. If we were to code this we wouldn't need to have a new put on shoe function for everyday, we could just have one put on shoe function that we loop every day when we leave the house.

Describe what the DOM is and an example of how you might interact with it.

If Javascript directly changed the html file It could permanently alter that document. So instead it alters the DOM (Document Object Model). The DOM is basically a replica of the html document that gets automatically synced with the html doc.

You would interact with the DOM if you wanted to make a button that changed some text. Using Javascript you could select some text and assign it a new string in the DOM. This would then be displayed on the web page without altering the original html.

Explain the difference between accessing data from arrays and objects.

Data in an object is given a name and a value. To access data from an object you call the name of each piece of data inside the object.

To access data from an array you select them using an index value. The Index value of the first piece of data is “0” For example, if you had the array, “example [data1, data2, data3]”. You would access data using, “example [i]” where i is the index number. “Example[0]” would give “data1”

Explain what functions are and why they are helpful.

A function is basically a set of tasks and instructions for the computer to follow. Functions are what actually manipulate information. Some basic examples of a function could be a + b or a - b.