HTML
CSS
Javascript
Defines the behavior of webpage
Add two numbers together
Change color when the user clicks
Load data from external source
Actions or "Verbs" of webpage
Like a Recipe
Follow Instructions one-by-one
Each step in a script is formed as a JavaScript statement
var name = "Daniel Kelly";
var age = 21;
var item1_price = 49.99;
var item2_price = 19.99;
var subtotal = item1_price + item2_price;
var overall_total = subtotal + (subtotal * 0.125);
var message = name ": Your total bill is: " + overall_total;
alert(message);Each step is executed one after another in sequence
If you want to enter multiple statements before executing, press Shift+Enter to go to new line without executing
//Different Types of Numbers
9
-10
//floating point numbers
3.14
//Math Operations
5 + 6
10.99 - 1.50
1 / 5
1.231 * 90Open Chrome JavaScript Console and Experiment (Ctrl+Shift+J)
//Modulus...(remainder)
10 % 3
14 % 5
//Order of Operations
(10-5) * 2
(8+12) * (10-5)Open Chrome JavaScript Console and Experiment (Ctrl+Shift+J)
Up: Previous Statement
Down: Next Statement
Open Chrome JavaScript Console and Experiment (Ctrl+Shift+J)
//Single or Double quotes can be used
"hello world"
'hello world'Sequence of characters
"string"//Combine Multiple Strings (Concatenation)
"Internet" + " Technologies"
"Daniel" + " " + "Kelly"Sequence of characters
"string"//Escape Characters start with a "\"
"This is a quote: \"Brevity is the soul of wit\" "
//Get the length of a string
"hello world".length
//Get individual characters using [] and index
"hello world"[0] //"h"
"hello world"[4] //"o"
Open Chrome JavaScript Console and Experiment (Ctrl+Shift+J)
//can only be true or false
true
falseOpen Chrome JavaScript Console and Eperiment (Ctrl+Shift+J)
//null and undefined are values
//there is not multiple types of null or undefined
null
undefined
Open Chrome JavaScript Console and Eperiment (Ctrl+Shift+J)
name
"This is my sentence data"
String Data:
sent1
"This is my sentence data"
String Data:
price
299
Number Data:
over18
True
Boolean Data:
var myVariable;Declare you are using a variable and what is name is
myVariable = 3;Assign a value to be stored in the variable
myVariable
3
sent1
"This is my sentence data"
String Data:
price
299
Number Data:
over18
True
Boolean Data:
var sent1;
sent1 = "This is my sentence data";var price;
price = 299;var over18;
over18 = true;//you can declare and assign in the same statement also
var myVariable = myValue;
//Variables can store numbers, string, booleans
var myStringVariable = "Hello";
var myNumberVariable = 414;
var myBooleanVariable = true;
//declare variable and assign value
var myName = "Daniel";
//call the variable to get its value
myname
Access stored values by calling the variable
myName
"Daniel"
//use the values of variables along with other values
"hello there " + myName; //"hello there Daniel"
Access stored values by calling the variable
//create variable and then use it in calculation
var price = 34.50;
5 + 17 + price; //56.5
//Change value of existing variable
price = 41.99;
//these variable have been declared
//...but NOT assigned a value
var firstName;
var surname;
Undefined:
When a variable has been declared but not give any value
//this variable is declared
//...it is also assigned a value
var voucherNo = "Voucher101"
//later if we want to set
//the voucher to "nothing"
//we assign it a null value
voucherNo = null; //expired
Null:
When you want to explicitly state the variable has no value
Organize Code in manageable chunks
Series of Statements that are grouped together because they perform a specific task.
Open Browser
Click on address bar
Type "learning.ulster.ac.uk"
Enter Username
Enter Password
Click "COM414"
Open COM414 Blackboard
Organize Code in manageable chunks
Series of Statements that are grouped together because they perform a specific task.
//1. Declare Function
function myFunction()
{
//code goes here
//do some stuff: step 1
//do some stuff: step 2
//do some stuff: step 3
}Organize Code in manageable chunks
Series of Statements that are grouped together because they perform a specific task.
//1. Declare Function
function myFunction()
{
//code goes here
var myVar = "Hello!!!"
var myVar2 = " World"
var combine = myVar + myVar2
}Organize Code in manageable chunks
Series of Statements that are grouped together because they perform a specific task.
//1. Declare Function
function myFunction()
{
//code goes here
var myVar = "Hello!!!"
var myVar2 = " World"
var combine = myVar + myVar2
return combine
}Organize Code in manageable chunks
Series of Statements that are grouped together because they perform a specific task.
//1. Declare Function
function myFunction()
{
//code goes here
var myVar = "Hello!!!"
return myVar;
}Organize Code in manageable chunks
//Declared Function
function myFunction()
{
var myVar = "Hello!!!"
return myVar;
}//Call Function
var myReturnedVar = myFunction();1->
2->
myReturnedVar
//"Hello!!!""Hello!!!"
Functions with Paramaters
//1. Declare Function
function calcSquared(value)
{
var squared = value * value;
return squared;
}Organize Code in manageable chunks
//Declared Function
function calcSquared(value)
{
var squared = value * value;
return squared;
}//Call Function
var mySqauredVal = calcSquared(5);1->
2->
mySquaredVal
//2525
25
5
5
Functions with multiple paramaters
//1. Declare Function
function calcPrice(cost,quantity)
{
var total = cost * quantity;
return total;
}Organize Code in manageable chunks
//Declared Function
function calcPrice(cost,quantity)
{
var total = cost * quantity;
return total;
}//Call Function
var price = calcPrice(2.99,10);1->
2->
price
//29.9029.90
29.90
2.99
10
Functions with Paramaters
//1. Declare Function
function calcPrice(cost,quantity)
{
var total = cost * quantity;
return total;
}//2. Call Function
var cost = 9.50;
var quantity = 2;
var myPrice = calcPrice(cost,quantity); //19.00
Function Challenges:
//1. Declared Function
function calcPrice(cost,quantity)
{
var total = cost * quantity;
return total;
}//2. Call Function
var price = calcPrice(2.99,10);Open Blank Replit
In the "script.js" file, edit it to create two functions:
Use the "console" on bottom right to enter commands to call your functions
Sample Code to Help:
Functions that someone else wrote...that we can use
//Alert Function
alert("Hello World!");
//Console Log function
console.log("Hello World!");
//Prompt function
prompt("What is you name?");var myName = prompt("What is you name?");<script src="myJavascriptFile.js"></script><!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1>Linking HTML and JS</h1>
<script src="myScript.js"></script>
</body>
</html>index.html
var name = prompt("Please Enter your Name");
alert("Welcome " + name);
console.log("Printing Name to Log: " + name);script.js
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1>Linking HTML and JS</h1>
<script src="myScript.js"></script>
</body>
</html>myHTMLFile.html
var name = prompt("Please Enter your Name");
alert("Welcome " + name);
console.log("Printing Name to Log: " + name);myScript.js
Edit the HTML file with some basic content (e.g. a h1 tag with basic heading)
Create JavaScript to do the following
Prompt user for first name
Prompt user for last name
Prompt user for age
In an alert, print out the users full name in a sentence
In the console, print out the users age in a sentence
Link the HTML with the Javascript File
Test the script