JavaScript

In order to make interactive web pages with jQuery, it's useful to know a few things about JavaScript.

JavaScript is a programming language that jQuery is written in, and knowing JavaScript will be helpful for understanding and writing your code.

The next cards will cover a few fundamental JavaScript concepts.

Javascript

Variables

var counter = 140;

Variables

var score1 = 23;
var score2 = 25;
var score3 = 21;

var sum = score1 + score2 + score3;
var average = sum / 3;

var range = score2 - score3;

var fraction = 23 / 30;
var percentage = fraction * 100;

Practice

Q:


Strings

var tweet = "Hiking trip on Saturday";

String length

var tweet = "Hiking trip on Saturday";
var tweetLength = tweet.length;

Comparisons

var score1 = 23;
var score2 = 6;
var counter = 140;
var tweet = "Hiking trip on Saturday";

score1 > score2;
tweet.length <= counter;
score1 === score2;

Practice

Q:


if

var myName = "Jordan";
var status = "";

if( myName.length >= 7 ) {
    status = "You have a long name!";
}

if...else

var myName = "Jordan";
var status = "";

if( myName.length >= 7 ) {
    status = "You have a long name!";
}
else {
    status = "You have a short name!";
}

if...else

var myName = "Michaelangelo";
var status;

if( myName.length >= 15 ) {
    status = "You have a very long name!";
}
else if( myName.length >= 7 ) {
    status = "You have a long name!";
}
else {
    status = "You have a short name!";
}

Functions

var percentage = function(num, denom) {
    var result = (num / denom) * 100;
    return result;
};

Functions

var percentage = function(num, denom) {
    var result = (num / denom) * 100;
    return result;
}

var p1 = percentage(23, 30);
  • ?