-
Time to code, fam.

-
-
Ok game time. Let’s learn some JavaScript.
Let’s review bootstrap / frontend frameworks
-
-
Let’s see if we can rebuild our layouts using a frontend framework.
Create a new project and then using the documentation provided by your the Bootstrap frontend framework, rebuild the following layouts.
-
NOTE: you will likely have to add some of your own CSS styles here as well to achieve the gray boxes and min-heights.
-
-
-
-
-
👇👇👇
-
Let’s begin by defining what javascript actually is, how we can load javascript into our webpages, and how we can write a few lines of super basic javascript syntax.
-
Originally called Mocha, then LiveScript, then renamed to JavaScript.
-
JavaScript runs in the browser, meaning it is used heavily in user-interaction. In other words, with javascript, you can…
-
You can use javascript to create for example an infinite random prop loop.
-
You can allow the user to take control of a UI element and dictate its state.
-
This is just a pretty cool masking example that is actually pretty hard to pull off with web dev tech (but can be done, as shown here thanks to javascript). (FYI: this formed the basis of this website that I built back in the day).
-
We are using something called conditionals here.
-
Basically, we can interact with API data without ever reloading the page!
-
NodeJS is a standalone port of Google Chrome’s v8 engine. Long story short, this allows us to run javascript on our machines in the same way you would run a “real” language such as ruby or python.
-
For this reason, we can today do essentially anything we could do with python/ruby/java/etc, namely:
👇👇👇
-
Discrete, highly logical and explicit instructions that are parsed and executed by a computer. We call this set of human-readable instructions source code, or colloquially, a computer program.
-
Compilers can take this source code and transform it into machine code, a representation of the source that can be executed by the computer’s central processing unit or CPU.
-
Not all programs are compiled though, some are interpreted. The difference is that compiled languages need a step where the source code is physically transformed into machine code. However, with an interpreted language, this additional step is excluded in favor of parsing and executing the source code directly when the program is run.
-
All programs are composed with a collection of fundamental concepts that, when combined, can essentially dictate a wide variety of tasks a computer can perform.
-
Declarations
Typically, we can store and retrieve data in our programs by associating them with intermediary values that we call variables
-
Expressions
We use expressions to evaluate stuff. For example, 2 + 2 is an example of an expression that will evaluate a value, namely 4.
NOTE: typically we can use expressions and declarations in tandem to perform complex tasks. For instance, we can reference a variable we declared in an expression to help us evaluate new values which can then be stored.
-
Statements
Statements will use expressions and declarations to alternate a program’s control flow, which is essentially the order in which declarations, expressions, and other statements are executed.
-
Aside from these fundamental concepts, we also talk a lot about this idea of algorithms. An algorithm is simply a series of declarations, expressions, and statements that can be used over and over again to solve well defined problems of a certain type.
-
For example, we can implement an algorithm that converts temperature from fahrenheit to celsius. It would look something like this:
-
This is a form of pseudo code where we define the steps a computer program — any — computer program can take to convert fahrenheit to celsius.
The beauty of programming is that all of it revolves around the same key set of concepts and ideas. For this reason, we do not need to specify any particular programming language when discussing the functional aspects of a program.
-
A programming language is a series of grammar and rules that we can define towards writing source code.
-
Languages are effectively different approaches towards communicating the same ideas in programming. Essentially, we can communicate in say both French and English, what mainly differs is the structure of our sentences and the actual words and sounds themselves. The same analogy can be made with programming languages.
-
-
These languages all build on the same concepts defined above; the main difference lies in how they are run (compiled vs interpreted) and also how they are used. In general, anything programmable can be programmed in each of the languages defined above. However, some languages are better suited for certain tasks above others. For example, to perform web programming on the front-end, you’ll want to write JavaScript. This is because all browsers collectively support running javascript within it’s environment.
-
Let’s build a thermostat.
Assumptions
👇👇👇
-
Before we begin, let us do some basic bookkeeping.
-
How do we set up javascript to run in the browser?
-
**NOTE the `<script>` tag**
-
1. This is a new tag we have never seen before; remember that the `<link>` tag is for CSS files and the `<script>` tag is for javascript files (for now).
2. the `src` attribute is what we use to link to the external js file
3. remember to CLOSE your script tag, unlike the `<link>` tag, `<script>` is NOT self closing!
-
**Commenting + ( basic debugging of ) code in JavaScript**
```js
// this is an inline comment
console.log('You can write debugging statements like so');
/*
this
is
a
multilined
comment
*/
-
Types of Variables
-
A variable type is a way to classify the different kinds of data we can save to a variable. There are exactly 6 types of variables:
-
undefinednull-
-
A Primitive type is a most basic bit of information that you can store. For example, a number is a primitive because it cannot be made up of any of the other types of variables Alternate definition: Think of this as an atom – atoms are atoms because we cannot break them down into any more basic bits, same goes for primitives
-
undefinedUndefined is the default state of any variable. Basically means the variable is empty or has not yet been assigned a value, primitive or otherwise
-
nullThe null variable is different from the undefined type, but only subtly so.
null type is assigned to a variable, but its “value” is empty.undefined type is by default the value of each variable that is declared but not defined-
True or false. Basically.
var myBooleanValue = true; // true
var myBooleanValueThatIsFalse = false; // false
console.log( typeof myBooleanValue );
-
Numeric values that can be operated upon via the standard rules of arithmetic.
var myNumber = 1;
var pi = 3.14159; // ...approximately
-
This one is interesting, we use this to represent text. Anything between the quotations (double or single, doesn’t matter as long as you are consistent) is treated as a number. So…
var myName = 'Taq Karim';
var dudeThisIsAString = '105';
var doubleQuotesRCool2 = "Look ma! I'm double quoted";
-
Objects are the bees-knees yo.
Objects are a collection of properties where each property is a primitive type.
-
// just primitives
var someNumber = 1;
var someBool = false;
var someNullItem = null;
// as an object...
var myObject = {
someNumber: 1,
someBool: false,
someNullItem: null,
}; // notice the use of ":" instead of "="
// to access these items:
console.log( myObject.someNumber );
console.log( myObject.someBool );