1) Please download Class 15 Starter Code
2) Move the following into class-work
:
click-count
light-switch
3) Soloution to accordion
and jquery-city
included
Final Projects:
⇒ Fourth deliverable due Wednesday, November 14th
⇒ JavaScript/Pseudocode
No Class:
⇒ Monday, 11/12
⇒ Wednesday, 11/21
Control Flow:
⇒ Order the CPU runs a program's statements
⇒ Decides which code is running at a given time
So far, our code has flowed sequentially
We can alter this flow using conditional logic
Sequential Control Flow:
⇒ Programs execute line by line, from top to bottom
Sequential Control Flow Example:
function sayHello() {
var name = $('input').val()
var greeting = 'Hello, ' + name + '!'
$('#output').text(greeting)
}
Programs can flow in other ways:
Conditonal Flow:
⇒ AKA if/else statements
⇒ Alters flow when a decision must be made
⇒ Choice is based on variables in the program
If/Else Flow:
Sequential vs. Conditional Flows:
var x = 10
if (x > 5) {
alert('x is larger than 5!')
} else {
alert('x is smaller than 5!')
}
Denoted by the if
and else
keywords
Begins with a condition: (x > 5)
If the condition is true, the statment(s) in the "if block" will run
If the condition is false, the statment(s) in the "else block" will run
===
equal to
!==
not equal to
>
greater than
<
less than
>=
greater than or equal to
<=
less than or equal to
var x = 10
if (x === 10) {
alert('bananas')
} else {
alert('apples')
}
var x = 'cat'
if (x !== 5) {
alert('tacos')
} else {
alert('salads')
}
var x = 10
if (x >= 10) {
alert('oranges')
} else {
alert('strawberries')
}
var x = 10
if (x <= 10) {
alert('kiwis')
} else {
alert('olives')
}
Programs can evaluate more than one condition
Use the else if
operator to handle:
var x = 10
if (x !== 10) {
alert('beer')
} else if (x === 10) {
alert('coffee')
} else {
alert('water')
}
1. Open click-count
in Sublime Text
2. Follow the instructions in js/app.js
3. Use if
, else if
, else
structure
.addClass('class-name')
⇒ Adds classes to elements
$('p').addClass('bold-text')
// would yield: <p class="bold-text"></p>
.removeClass('class-name')
⇒ Removes classes from elements
$('p').removeClass('bold-text')
.toggleClass('class-name')
⇒ Adds class to elements if it does not exist; otherwise removes
Assuming the following HTML:
<p>Some Paragraph</p>
$('p').toggleClass('bold-text')
// would yield: <p class="bold-text"></p>
1. Open light-switch
in Sublime Text
2. Follow the instructions in js/app.js
Function Arguments
HTML Insertion/Removal