CIS 111 Lecture Notes - Lecture 3: Cascading Style Sheets, Web Application

42 views5 pages
Chpts 4,9,18,21,22,23 (Wk 3)
What we will cover in class
o Function Expressions
o Program Structure
o Chpt 9: Where Should Your Code Live?
o Chpt 4: Conditional Statements & Logic Operators
o Chpt 5: Meet the Loops
o Chpts 21-23: Meet the DOM
Function Declaration
o There are several ways to create a function in JavaScript
First one is to use a function declaration.
//function declaration
function myFunction(param1, param2, …) {
//function code using param1, param2, …
}
//function call
myFunction(arg1, arg2, …);
Notes
o Function definitions go at top
o Followed by IPO code
o Stored in a .js file
Chpt 9: Separate .html & .js files
o Referencing the .js file
Once you have your JavaScript file created, the second (and final) step is to
reference it in the HTML page. This is handled by your script tag. More
specifically, it is handled by your script tag’s src attribute that points to the
location of your JavaScript file:
<!DOCTYPE html>
<html>
<body>
<h1>Example</h1>
<script src=”example.js”></script>
</body>
</html>
Chpt 4: Conditional Statements & Logic Ops
o Aka Selection Statements
Problems that require an if statement to solve
maxOf2
isFactor
Unlock document

This preview shows pages 1-2 of the document.
Unlock all 5 pages and 3 million more documents.

Already have an account? Log in
Chpts 4,9,18,21,22,23 (Wk 3)
safeToProceed
isWeekEnd
isNaturalSeven
isAlpha
Is pf a factor of n?
var isFactor=function(n,pf)
if(n%pf==0) {
return true;
}
else
return false;
}
If statement => Fork in the Road
var Safe_To_Proceed=true; //global symbolic constant
if(Safe_To_Proceed==true) {
alert(“You shall pass!”);
} else {
alert(‘“You shall not pass!”, quoth Gandalf.’);
}
Conditional Operators
o Expression: anything that gives you a value
o Condition: an expression that evaluates to true or false
Conditions are constructed using comparison operators and logic operators
Operator
When True
==
first expression evaluates to something equal to 2nd one
>=
first expression evaluates to something greater than or equal to 2nd
one
>
first expression evaluates to something greater than 2nd one
<=
first expression evaluates to something lesser than or equal to 2nd one
Unlock document

This preview shows pages 1-2 of the document.
Unlock all 5 pages and 3 million more documents.

Already have an account? Log in

Document Summary

More specifically, it is handled by your script tag"s src attribute that points to the location of your javascript file: example fork in the road var safe_to_proceed=true; //global symbolic constant if(safe_to_proceed==true) { alert( you shall pass! ); } else { alert( you shall not pass! , quoth gandalf. "): conditional operators, expression: anything that gives you a value, condition: an expression that evaluates to true or false, conditions are constructed using comparison operators and logic operators. In javascript, days of the week are (0-6), where 0 is sin, 1 is mon, . //recognizer for weekends var isweekend=function(d){ var today = 5; alert(isweekend(today)); //returns false: natural seven .

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers