Intro to Programming (in JavaScript)
What is programming, anyway?
Programming gives computers a series of instructions… And it all renders down to binary (0s and 1s)!
Programming Languages There are SO MANY programming languages… today we’re learning JavaScript, an easy language to get started with.
JavaScript Doesn’t really have anything to do with Java Executed by web browsers (usually) GREAT language to learn Very in-demand due to growing popularity of JavaScript frameworks for front-end (user interface) and back-end (server) development
Let’s get started… You don’t need a code editor to write JavaScript. You can use anything, even just Notepad. We are going to create an HTML file, like we did Monday, and write the JavaScript there.
Instructions: Getting Started Open Notepad Type the HTML code on the right side of this slide. Save the file as learnjs.html Change save as type to All Files Then double-click the saved file to open it in a web browser
Basic Processing Change your previous code to the following… Save the file and refresh the page in your browser Let’s break it down…
Variables Store information to be accessed and/or processed later
Variables Can be used virtually anywhere in your code
Variable Types JavaScript variables are loosely assigned, so you don’t need to declare a variable type When you work with some other languages, this will not be the case! Common variable types: String: “this is text!” Integer: 4 Double: 4.2 Boolean: false
Working with Different Variable Types
Working with Concatenation
Conditional Statements Now let’s ask the computer to make some decisions!
Conditional Statements Change the number in the conditional statement
If… else
If… else if… else
Comparison Operators > greater than >= greater than or equal to < less than <= less than or equal to == equals !== does not equal
You try it! Create a variable x with a value of 11 Create a variable y with a value of 15 Write a conditional statement to check if x is greater than y. If so, output the result of x + y But, if x is less than y, output the result of y - x What is the result?
Loops Sometimes, we need to perform an action repeatedly while a condition is satisfied – for this, we have loops! How would you add a space between each number displayed?
Functions Sometimes, we want to define instructions that can be repeated multiple times…
Functions Or, triggered from HTML!
HTML Forms
Processing HTML Forms
Objects/Classes Very important programming concept Objects are used to organize code, prevent coding errors, and define a set of functions and variables relevant only to their intended scope
Object Parameters Sometimes, we want to create an object with established parameters from the beginning These are created in the constructor
Bringing It Together…