- The HTML gives the page structure
(THE CONTENT LAYER) - The CSS is the design for the HTML and state how content is presented
(THE PRESENTATION LAYER) - The JAVASCRIPT will add interactivity to the web page
(BEHAVIOR LAYER)
<!DOCTYPE html>
<html>
<head>
<title>Constructive & Co.</ title>
<link rel ="stylesheet" href="css/ cOl.css" />
</ head>
<body>
<hl>Constructive & ; Co. </ hl>
<script src="js/ add-content.js"></ script>
<p>For all orders and i nquiries please cal l
<em>SSS-3344</ em></ p>
</ body>
</html>
-
JavaScript runs where its is found in the HTML
-
When the browser comes across a
<script>element, it stops to load the script and then checks to see if it needs to do anything.
It is best to keep JavaScript code in its own JavaScript file
- Statements should end with a semicolon Example
var today= new Date{);
var hourNow = today.getHours{) ;
var greeting;
if (hourNow > 18) {
greeting= 'Good evening';
else if (hourNow > 12) {
greeting= 'Good afternoon';
else if (hourNow > O) {
greeting 'Good morning';
else {
greeting 'Welcome';
document.write(greeting) ;
JavaScript is a CASE SENSITIVE
- We can use comments to explain what the code does
MULTI-LINE COMM ENTS we start with
/*and end with*\characters SINGLE-LINE COMMENTS we start with//anything that follows the two forward slash characters will not be processed by JavaScript
the data stored in a variable can change each time a script runs. and we can assign a value to them.
- Numeric Data
45 - String Data
'Hello, There' - Boolean Data
true
Example for Using variable to store a number
var price;
var quantity;
var total;
price = 5;
quantity = 14;
total = price * quantity;
var el = document.getElementByid( ' cost ');
el .textContent = '$' +total;