SlideShare a Scribd company logo
1 of 47
Download to read offline
FEWD - WEEK 6
WILL MYERS
Freelance Front End Developer
SLIDES
http://www.slideshare.net/wilkom/fewd-week6-slides
YOUR WEEKLY FEWD GITHUB
REPOSITORY
Use the '+' button in the top-left of GitHub Desktop
(Create tab)
Create a new repository called 'FEWD_Week6'
Choose the [home]/FEWD folder for the local path
Open this repo folder in your editor
Commit the changes and publish the FEWD_Week6
repository to github.com
YOUR WEEKLY WORKING FILES
FROM ME
To get the week6_working_files you should just be able to
select the ga-fewd-files repository in GitHub Desktop and
press 'Sync'. This should pull in this weeks folder from
github.com.
If you any difficulties you should just re-clone the ga-fewd-
files repository.
Copy the whole week6_working_files into your FEWD_Week6
repository and commit and publish to github.com
REVIEW OF LAST WEEK'S
ASSIGNMENT
AGENDA
Collection Of Data
Manipulating Collections
ARRAYS COLLECTIONS
ARRAYS
What if we had a collection of images that we wanted to
display to the screen one at a time?
How could we store all the images?
ARRAYS
An array is a list object with built in methods for things like:
adding to the list
removing from the list
traversal of the list.
DECLARING ARRAYS
var myArr = new Array();
declaring an empty array using the Array constructor.
DECLARING ARRAYS
var myArr = [ ];
declaring an empty array using literal notation.
DECLARING ARRAYS
myArr = ['Hello', 54.3, true];
Arrays are filled with elements: i.e. myArr3 = [element,
anotherElement];
Elements can contain strings, numbers, booleans, and
more.
DECLARING ARRAYS
If you leave a blank spot in an array it creates a blank shelf
space (undefined) placeholder.
ARRAYS INDEXING
ARRAYS INDEXING
Array elements can be fetched by their index number (starts
from 0).
myArr = ['Hello', , 54.3, true];
console.log(myArr[0]); //prints Hello
console.log(myArr[1]); //prints undefined
console.log(myArr[2]); //prints 54.3
console.log(myArr[3]); //prints true
ARRAYS INDEXING
We can insert new values into any space in the array using
the positions index.
myArr[1] = 'Stuff';
ARRAYS INDEXING
We can overwrite all the elements of an array simply by
giving the array new values or by setting an array equal to a
different array.
var fruits = ['Apples', 'Oranges', 'Pears', 'Bananas'];
var myArr=[1,2,3];
myArr = fruits;
console.log(myArr); //prints Apples, Oranges, Pears, Bananas
ARRAY LENGTH
What if I would like to know how long my array is (how many
elements)?
console.log(myArr.length); //prints 4
ARRAY METHODS
The Array object has many built in methods for doing stuff
with arrays. Here are two common methods:
Array.push()adds an item to the end of an array
var myArr = [1,2,3];
myArr.push(4); //myArr === [1,2,3,4]
Array.pop()removes an item from the end of an array
var myArr = [1,2,3,4];
var popped = myArr.pop(); //myArr === [1,2,3]; popped = 4;
ARRAYS EXERCISE
Open week5_working_files/arrays_exercise
ITERATE OVER ARRAY
Computers can repeatedly execute lines of code very
quickly (in milliseconds and nanoseconds)
Combined with conditions (if) computers can process
large quantities of data quickly and make "intelligent"
decisions based on this data.
Sequentially processing a list of data and doing
something with the data is one of the most common
activities in programming.
ITERATE OVER ARRAY - REPEAT LOOPS
forloop:
for (var i = 0; i < 5; i++) {
//i runs from 0 to 4 in this loop.
};
whileloop:
var n = 10;
while(n--){
console.log('n is', n); //n runs from 9 to 0
};
ITERATE OVER ARRAY
The Array.forEachmethod also allows you to run code
using each element from the array as a value
You pass an anonymous function with pre-defined
arguments
var fruits=["Banana","Apple","Pear"]
fruits.forEach(function(element,index){
console.log(element, "is at position", index);
});
elementis the item from the array
indexis the item's position in the array
MORE ON ARRAYS
For many more Array methods see:โ€‹
https://developer.mozilla.org/en-
US/docs/JavaScript/Reference/Global_Objects/Array
CAROUSEL
Open week5_working_files/carousel_animals
WEATHER APPLICATION
Can you build a weather application that works in the same
way as your CitiPix assignment?
The user inputs a temperature in Celsius
This temperature gets converted to Fahrenheit and
displayed on the page
Change the display of an image on the page if the
temperature is cold or hot (< 20 degrees Celsius or >= 20
degrees Celsius)
ROCK PAPER SCISSORS
Open week6_working_files/rock_paper_scissors
AGENDA
Refactor
This Keyword
Debugging Techniques
REFACTOR
Making code more efficient without changing
functionality.
REFACTOR
The process of rewriting code without changing
functionality
To reduce or eliminate redundancy
Make code easier to read
Make code more maintainable
CSS REFACTOR
Remove inline styling
Replace repeated styles with classes
Rename classes/ids for readability
Organize CSS
Group by section
Order by precedence (tag selectors at top, id selectors at
bottom)
Create classes for large CSS changes in JS
Remove unnecessary css
JS REFACTOR
Use functions
Use variables
Use arrays
Combine jQuery selectors
Combine jQuery property changes into objects
.css,.attr,etc
Chain jQuery function calls
REFACTOR
Open week6_working_files/refactor
SWITCH BLOCKS
When you end up writing a lot if ... elsesyntax in your
code (for example in the Rock Paper Scissors game) you can
use a different syntax (as follows) to make your code a bit
cleaner and clearer:
switch(someValue){
case "value1":
doThis();
break;
case "value2":
doThat();
break;
default:
doSomethingElse();
}
It is important have the break;keyword at the end of each
casestatement, so as to exit the switchblock correctly.
SWITCH BLOCKS
Let's refactor Rock Paper Scissors with a switchblock
KEYWORD: "THIS"
In JavaScript thisis the keyword for a context object. It is
used inside a function block.
You can think of the context as the owner of a function.
If you write a function in the global context, then thiswill
refer to the global windowobject.
//written in the global window context of your JavaScript file
function doSomething(){
return this; //this refers to the global window object
}
console.log (doSomething() === window);// returns true
KEYWORD: "THIS"
When you attach a function as an event handler to an HTML
element, then the element becomes the owner of the
function and so thiswill refer to the element.
element.onclick = doSomething;
See this link for more info on when thisrefers to an HTML
element: http://www.quirksmode.org/js/this.html
KEYWORD: "THIS" IN JQUERY
jQuery uses thiswrapped in a jQuery selection, so that it
can call jQuery methods directly on the selected element.
If you wrap thisin jQuery - $(this)- in your handler, it
will refer to the element you have selected using jQuery.
See this codepen: http://codepen.io/wilkom/pen/xZjeWz
KEYWORD: "THIS" IN JQUERY
This is useful when you are applying the same event handler
to a group elements and you want each element to work
independently.
$("p").on("click",function(e){
$(this).fadeOut(500);
});
Rule of thumb (ROT): If I don't know what thing will be acted
on, then I should consider using "this"
REFACTOR USING THIS
Open week6_working_files/color_scheme
DEBUGGING
Why isn't this working?
DEBUGGING
Always start be defining the problem.
"The image is not moving"
"None of my code works"
DEBUGGING
This will tell you where to start your hunt
Image not moving
find the code that makes the image move
None of my code works
Syntax error, check console
DEBUGGING: LEVEL 1
Check for errors (red text, aligned right) in console To access
debugging console
PC: CTRL+SHIFT+J
Mac: COMMAND+OPTION+J
Click the error
The location may not be correct but is a good place to start
Ex: Unbalanced brackets or parentheses
DEBUGGING: LEVEL 2
So no red errors but not getting the right answer? Try
console.log
Ex:
var stringOfNames="";
["Bob","Joe"].forEach(function(element){
stringOfNames-=element+",";
console.log(stringOfNames);
});
DEBUGGING: LEVEL 3
Use the debugger in Chrome
Set a breakpoint
Run the code
Step through the code until you get to the error
Variable values display on the right
You can switch to the console to run code or check value
of variable
DEBUGGING: LEVEL 4
Get help!
1. Try "Your preferred search engine" search
2. Be ready to clearly articulate the problem (Write out what
your problem is)
3. If nothing, ask instructor
DEBUG
Open week6_working_files/debug

More Related Content

What's hot

SproutCore is Awesome - HTML5 Summer DevFest
SproutCore is Awesome - HTML5 Summer DevFestSproutCore is Awesome - HTML5 Summer DevFest
SproutCore is Awesome - HTML5 Summer DevFesttomdale
ย 
Putting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For Koha
Putting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For KohaPutting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For Koha
Putting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For KohaGalen Charlton
ย 
Everything You (N)ever Wanted to Know about Testing View Controllers
Everything You (N)ever Wanted to Know about Testing View ControllersEverything You (N)ever Wanted to Know about Testing View Controllers
Everything You (N)ever Wanted to Know about Testing View ControllersBrian Gesiak
ย 
Design for succcess with react and storybook.js
Design for succcess with react and storybook.jsDesign for succcess with react and storybook.js
Design for succcess with react and storybook.jsChris Saylor
ย 
Violet Peรฑa - Storybook: A React Tool For Your Whole Team
Violet Peรฑa - Storybook: A React Tool For Your Whole TeamViolet Peรฑa - Storybook: A React Tool For Your Whole Team
Violet Peรฑa - Storybook: A React Tool For Your Whole TeamAnton Caceres
ย 
Ember and containers
Ember and containersEmber and containers
Ember and containersMatthew Beale
ย 
jQuery 1.7 Events
jQuery 1.7 EventsjQuery 1.7 Events
jQuery 1.7 Eventsdmethvin
ย 
Testing view controllers with Quick and Nimble
Testing view controllers with Quick and NimbleTesting view controllers with Quick and Nimble
Testing view controllers with Quick and NimbleMarcio Klepacz
ย 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projectsIgnacio Martรญn
ย 
Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React Robert DeLuca
ย 
Hidden Treasures in Project Wonder
Hidden Treasures in Project WonderHidden Treasures in Project Wonder
Hidden Treasures in Project WonderWO Community
ย 
Quick: Better Tests via Incremental Setup
Quick: Better Tests via Incremental SetupQuick: Better Tests via Incremental Setup
Quick: Better Tests via Incremental SetupBrian Gesiak
ย 
jQuery in 15 minutes
jQuery in 15 minutesjQuery in 15 minutes
jQuery in 15 minutesSimon Willison
ย 
Complex Architectures in Ember
Complex Architectures in EmberComplex Architectures in Ember
Complex Architectures in EmberMatthew Beale
ย 
Owl: The New Odoo UI Framework
Owl: The New Odoo UI FrameworkOwl: The New Odoo UI Framework
Owl: The New Odoo UI FrameworkOdoo
ย 
Ruby - Design patterns tdc2011
Ruby - Design patterns tdc2011Ruby - Design patterns tdc2011
Ruby - Design patterns tdc2011Rafael Felix da Silva
ย 
amsterdamjs - jQuery 1.5
amsterdamjs - jQuery 1.5amsterdamjs - jQuery 1.5
amsterdamjs - jQuery 1.5mennovanslooten
ย 
Containers & Dependency in Ember.js
Containers & Dependency in Ember.jsContainers & Dependency in Ember.js
Containers & Dependency in Ember.jsMatthew Beale
ย 
The effective use of Django ORM
The effective use of Django ORMThe effective use of Django ORM
The effective use of Django ORMYaroslav Muravskyi
ย 

What's hot (20)

SproutCore is Awesome - HTML5 Summer DevFest
SproutCore is Awesome - HTML5 Summer DevFestSproutCore is Awesome - HTML5 Summer DevFest
SproutCore is Awesome - HTML5 Summer DevFest
ย 
Putting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For Koha
Putting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For KohaPutting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For Koha
Putting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For Koha
ย 
Everything You (N)ever Wanted to Know about Testing View Controllers
Everything You (N)ever Wanted to Know about Testing View ControllersEverything You (N)ever Wanted to Know about Testing View Controllers
Everything You (N)ever Wanted to Know about Testing View Controllers
ย 
Design for succcess with react and storybook.js
Design for succcess with react and storybook.jsDesign for succcess with react and storybook.js
Design for succcess with react and storybook.js
ย 
Violet Peรฑa - Storybook: A React Tool For Your Whole Team
Violet Peรฑa - Storybook: A React Tool For Your Whole TeamViolet Peรฑa - Storybook: A React Tool For Your Whole Team
Violet Peรฑa - Storybook: A React Tool For Your Whole Team
ย 
Ember and containers
Ember and containersEmber and containers
Ember and containers
ย 
jQuery 1.7 Events
jQuery 1.7 EventsjQuery 1.7 Events
jQuery 1.7 Events
ย 
Testing view controllers with Quick and Nimble
Testing view controllers with Quick and NimbleTesting view controllers with Quick and Nimble
Testing view controllers with Quick and Nimble
ย 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projects
ย 
Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React
ย 
Hidden Treasures in Project Wonder
Hidden Treasures in Project WonderHidden Treasures in Project Wonder
Hidden Treasures in Project Wonder
ย 
Quick: Better Tests via Incremental Setup
Quick: Better Tests via Incremental SetupQuick: Better Tests via Incremental Setup
Quick: Better Tests via Incremental Setup
ย 
jQuery in 15 minutes
jQuery in 15 minutesjQuery in 15 minutes
jQuery in 15 minutes
ย 
Complex Architectures in Ember
Complex Architectures in EmberComplex Architectures in Ember
Complex Architectures in Ember
ย 
Advanced redux
Advanced reduxAdvanced redux
Advanced redux
ย 
Owl: The New Odoo UI Framework
Owl: The New Odoo UI FrameworkOwl: The New Odoo UI Framework
Owl: The New Odoo UI Framework
ย 
Ruby - Design patterns tdc2011
Ruby - Design patterns tdc2011Ruby - Design patterns tdc2011
Ruby - Design patterns tdc2011
ย 
amsterdamjs - jQuery 1.5
amsterdamjs - jQuery 1.5amsterdamjs - jQuery 1.5
amsterdamjs - jQuery 1.5
ย 
Containers & Dependency in Ember.js
Containers & Dependency in Ember.jsContainers & Dependency in Ember.js
Containers & Dependency in Ember.js
ย 
The effective use of Django ORM
The effective use of Django ORMThe effective use of Django ORM
The effective use of Django ORM
ย 

Viewers also liked

Cuadro Comparativo
Cuadro ComparativoCuadro Comparativo
Cuadro ComparativoArleth Orellana
ย 
Designing for Online Collaborative Sensemaking
Designing for Online Collaborative SensemakingDesigning for Online Collaborative Sensemaking
Designing for Online Collaborative SensemakingNitesh Goyal
ย 
Machine learning
Machine learningMachine learning
Machine learningAlex Vermeulen
ย 
Week van de Mobiliteit 2015
Week van de Mobiliteit  2015Week van de Mobiliteit  2015
Week van de Mobiliteit 2015Ans Huisman
ย 
Boletรญn Semestral INPPARES Informa (Semestre 1/ Ene - Jun 2015 )
Boletรญn Semestral INPPARES Informa (Semestre 1/ Ene - Jun 2015 )Boletรญn Semestral INPPARES Informa (Semestre 1/ Ene - Jun 2015 )
Boletรญn Semestral INPPARES Informa (Semestre 1/ Ene - Jun 2015 )INPPARES / Perรบ
ย 
The Percheron horses:
The Percheron horses:The Percheron horses:
The Percheron horses:DrMuhammadAshiq
ย 
Milvia pinedaa5
Milvia pinedaa5Milvia pinedaa5
Milvia pinedaa5Milvia Pineda
ย 
Gastronomรญa 2.0 en la red
Gastronomรญa 2.0  en la redGastronomรญa 2.0  en la red
Gastronomรญa 2.0 en la redJavier Camacho
ย 
Chem 2 - Acid-Base Equilibria IV: Calculating the pH of Strong Acids versus W...
Chem 2 - Acid-Base Equilibria IV: Calculating the pH of Strong Acids versus W...Chem 2 - Acid-Base Equilibria IV: Calculating the pH of Strong Acids versus W...
Chem 2 - Acid-Base Equilibria IV: Calculating the pH of Strong Acids versus W...Lumen Learning
ย 
Turismo en entornos competitivos
Turismo en entornos competitivosTurismo en entornos competitivos
Turismo en entornos competitivosJavier Camacho
ย 
Higiene y Seguridad Industrial
Higiene y Seguridad IndustrialHigiene y Seguridad Industrial
Higiene y Seguridad Industrial'Crlooz Mรกrqez
ย 
La Educaciรณn Sexual Integral en la Prevenciรณn de la Violencia.
La Educaciรณn Sexual Integral en la Prevenciรณn de la Violencia.La Educaciรณn Sexual Integral en la Prevenciรณn de la Violencia.
La Educaciรณn Sexual Integral en la Prevenciรณn de la Violencia.INPPARES / Perรบ
ย 
Abordaje preventivo del duelo complicado en unidades de hospitalizaciรณn
Abordaje preventivo del duelo complicado en unidades de hospitalizaciรณnAbordaje preventivo del duelo complicado en unidades de hospitalizaciรณn
Abordaje preventivo del duelo complicado en unidades de hospitalizaciรณnCentro de Humanizaciรณn de la Salud
ย 
1.9 temperatura y ley cero de la termodinamica
1.9 temperatura y ley cero de la termodinamica1.9 temperatura y ley cero de la termodinamica
1.9 temperatura y ley cero de la termodinamicaTersy Comi Gonzalez
ย 
Introducciรณn a la ingenierรญa
Introducciรณn a la ingenierรญaIntroducciรณn a la ingenierรญa
Introducciรณn a la ingenierรญaUniversidad Libre
ย 
Marca Sevilla by Sevilla Tourism Week
Marca Sevilla by Sevilla Tourism WeekMarca Sevilla by Sevilla Tourism Week
Marca Sevilla by Sevilla Tourism WeekJavier Camacho
ย 
Trabajo sobre el sida
Trabajo sobre el sida Trabajo sobre el sida
Trabajo sobre el sida septimogrado
ย 

Viewers also liked (20)

Cuadro Comparativo
Cuadro ComparativoCuadro Comparativo
Cuadro Comparativo
ย 
Designing for Online Collaborative Sensemaking
Designing for Online Collaborative SensemakingDesigning for Online Collaborative Sensemaking
Designing for Online Collaborative Sensemaking
ย 
Mapa de riesgo
Mapa de riesgoMapa de riesgo
Mapa de riesgo
ย 
Machine learning
Machine learningMachine learning
Machine learning
ย 
Week van de Mobiliteit 2015
Week van de Mobiliteit  2015Week van de Mobiliteit  2015
Week van de Mobiliteit 2015
ย 
Boletรญn Semestral INPPARES Informa (Semestre 1/ Ene - Jun 2015 )
Boletรญn Semestral INPPARES Informa (Semestre 1/ Ene - Jun 2015 )Boletรญn Semestral INPPARES Informa (Semestre 1/ Ene - Jun 2015 )
Boletรญn Semestral INPPARES Informa (Semestre 1/ Ene - Jun 2015 )
ย 
The Percheron horses:
The Percheron horses:The Percheron horses:
The Percheron horses:
ย 
Milvia pinedaa5
Milvia pinedaa5Milvia pinedaa5
Milvia pinedaa5
ย 
Gastronomรญa 2.0 en la red
Gastronomรญa 2.0  en la redGastronomรญa 2.0  en la red
Gastronomรญa 2.0 en la red
ย 
Chem 2 - Acid-Base Equilibria IV: Calculating the pH of Strong Acids versus W...
Chem 2 - Acid-Base Equilibria IV: Calculating the pH of Strong Acids versus W...Chem 2 - Acid-Base Equilibria IV: Calculating the pH of Strong Acids versus W...
Chem 2 - Acid-Base Equilibria IV: Calculating the pH of Strong Acids versus W...
ย 
Turismo en entornos competitivos
Turismo en entornos competitivosTurismo en entornos competitivos
Turismo en entornos competitivos
ย 
Higiene y Seguridad Industrial
Higiene y Seguridad IndustrialHigiene y Seguridad Industrial
Higiene y Seguridad Industrial
ย 
La Educaciรณn Sexual Integral en la Prevenciรณn de la Violencia.
La Educaciรณn Sexual Integral en la Prevenciรณn de la Violencia.La Educaciรณn Sexual Integral en la Prevenciรณn de la Violencia.
La Educaciรณn Sexual Integral en la Prevenciรณn de la Violencia.
ย 
Abordaje preventivo del duelo complicado en unidades de hospitalizaciรณn
Abordaje preventivo del duelo complicado en unidades de hospitalizaciรณnAbordaje preventivo del duelo complicado en unidades de hospitalizaciรณn
Abordaje preventivo del duelo complicado en unidades de hospitalizaciรณn
ย 
1.9 temperatura y ley cero de la termodinamica
1.9 temperatura y ley cero de la termodinamica1.9 temperatura y ley cero de la termodinamica
1.9 temperatura y ley cero de la termodinamica
ย 
Introducciรณn a la ingenierรญa
Introducciรณn a la ingenierรญaIntroducciรณn a la ingenierรญa
Introducciรณn a la ingenierรญa
ย 
e paper seminar
e paper seminare paper seminar
e paper seminar
ย 
Marca Sevilla by Sevilla Tourism Week
Marca Sevilla by Sevilla Tourism WeekMarca Sevilla by Sevilla Tourism Week
Marca Sevilla by Sevilla Tourism Week
ย 
Trabajo sobre el sida
Trabajo sobre el sida Trabajo sobre el sida
Trabajo sobre el sida
ย 
Sexualidad y discapacidad
Sexualidad y discapacidadSexualidad y discapacidad
Sexualidad y discapacidad
ย 

Similar to Fewd week6 slides

Fewd week5 slides
Fewd week5 slidesFewd week5 slides
Fewd week5 slidesWilliam Myers
ย 
Webpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San FranciscoWebpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San FranciscoRyan Weaver
ย 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e bigAndy Peterson
ย 
Neo4j Stored Procedure Training Part 1
Neo4j Stored Procedure Training Part 1Neo4j Stored Procedure Training Part 1
Neo4j Stored Procedure Training Part 1Max De Marzi
ย 
Grails 0.3-SNAPSHOT Presentation WJAX 2006 English
Grails 0.3-SNAPSHOT Presentation WJAX 2006 EnglishGrails 0.3-SNAPSHOT Presentation WJAX 2006 English
Grails 0.3-SNAPSHOT Presentation WJAX 2006 EnglishSven Haiges
ย 
Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolGordon Forsythe
ย 
Getting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascriptGetting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascriptMohd Saeed
ย 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial EnAnkur Dongre
ย 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial EnAnkur Dongre
ย 
Professional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsProfessional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsMike Wilcox
ย 
Template rendering in rails
Template rendering in rails Template rendering in rails
Template rendering in rails Hung Wu Lo
ย 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsJeff Durta
ย 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsAlessandro Molina
ย 
Connect.js - Exploring React.Native
Connect.js - Exploring React.NativeConnect.js - Exploring React.Native
Connect.js - Exploring React.Nativejoshcjensen
ย 
Ajax, JSF, Facelets, Eclipse & Maven tutorials
Ajax, JSF, Facelets, Eclipse & Maven tutorialsAjax, JSF, Facelets, Eclipse & Maven tutorials
Ajax, JSF, Facelets, Eclipse & Maven tutorialsRaghavan Mohan
ย 
Intro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScriptIntro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScriptjasonsich
ย 
WordPress Structure and Best Practices
WordPress Structure and Best PracticesWordPress Structure and Best Practices
WordPress Structure and Best Practicesmarkparolisi
ย 
Introduction to Redux (for Angular and React devs)
Introduction to Redux (for Angular and React devs)Introduction to Redux (for Angular and React devs)
Introduction to Redux (for Angular and React devs)Fabio Biondi
ย 

Similar to Fewd week6 slides (20)

Fewd week5 slides
Fewd week5 slidesFewd week5 slides
Fewd week5 slides
ย 
Webpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San FranciscoWebpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San Francisco
ย 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e big
ย 
Neo4j Stored Procedure Training Part 1
Neo4j Stored Procedure Training Part 1Neo4j Stored Procedure Training Part 1
Neo4j Stored Procedure Training Part 1
ย 
Grails 0.3-SNAPSHOT Presentation WJAX 2006 English
Grails 0.3-SNAPSHOT Presentation WJAX 2006 EnglishGrails 0.3-SNAPSHOT Presentation WJAX 2006 English
Grails 0.3-SNAPSHOT Presentation WJAX 2006 English
ย 
Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_Tool
ย 
Getting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascriptGetting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascript
ย 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
ย 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
ย 
Professional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsProfessional JavaScript: AntiPatterns
Professional JavaScript: AntiPatterns
ย 
Template rendering in rails
Template rendering in rails Template rendering in rails
Template rendering in rails
ย 
backend
backendbackend
backend
ย 
backend
backendbackend
backend
ย 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
ย 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable Applications
ย 
Connect.js - Exploring React.Native
Connect.js - Exploring React.NativeConnect.js - Exploring React.Native
Connect.js - Exploring React.Native
ย 
Ajax, JSF, Facelets, Eclipse & Maven tutorials
Ajax, JSF, Facelets, Eclipse & Maven tutorialsAjax, JSF, Facelets, Eclipse & Maven tutorials
Ajax, JSF, Facelets, Eclipse & Maven tutorials
ย 
Intro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScriptIntro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScript
ย 
WordPress Structure and Best Practices
WordPress Structure and Best PracticesWordPress Structure and Best Practices
WordPress Structure and Best Practices
ย 
Introduction to Redux (for Angular and React devs)
Introduction to Redux (for Angular and React devs)Introduction to Redux (for Angular and React devs)
Introduction to Redux (for Angular and React devs)
ย 

More from William Myers

Fewd week8 slides
Fewd week8 slidesFewd week8 slides
Fewd week8 slidesWilliam Myers
ย 
Fewd week7 slides
Fewd week7 slidesFewd week7 slides
Fewd week7 slidesWilliam Myers
ย 
Fewd week4 slides
Fewd week4 slidesFewd week4 slides
Fewd week4 slidesWilliam Myers
ย 
Fewd week3 slides
Fewd week3 slidesFewd week3 slides
Fewd week3 slidesWilliam Myers
ย 
Fewd week2 slides
Fewd week2 slidesFewd week2 slides
Fewd week2 slidesWilliam Myers
ย 
Fewd week1 slides
Fewd week1 slidesFewd week1 slides
Fewd week1 slidesWilliam Myers
ย 
Pfnp slides
Pfnp slidesPfnp slides
Pfnp slidesWilliam Myers
ย 

More from William Myers (7)

Fewd week8 slides
Fewd week8 slidesFewd week8 slides
Fewd week8 slides
ย 
Fewd week7 slides
Fewd week7 slidesFewd week7 slides
Fewd week7 slides
ย 
Fewd week4 slides
Fewd week4 slidesFewd week4 slides
Fewd week4 slides
ย 
Fewd week3 slides
Fewd week3 slidesFewd week3 slides
Fewd week3 slides
ย 
Fewd week2 slides
Fewd week2 slidesFewd week2 slides
Fewd week2 slides
ย 
Fewd week1 slides
Fewd week1 slidesFewd week1 slides
Fewd week1 slides
ย 
Pfnp slides
Pfnp slidesPfnp slides
Pfnp slides
ย 

Recently uploaded

On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024APNIC
ย 
WhatsApp ๐Ÿ“ž 8448380779 โœ…Call Girls In Mamura Sector 66 ( Noida)
WhatsApp ๐Ÿ“ž 8448380779 โœ…Call Girls In Mamura Sector 66 ( Noida)WhatsApp ๐Ÿ“ž 8448380779 โœ…Call Girls In Mamura Sector 66 ( Noida)
WhatsApp ๐Ÿ“ž 8448380779 โœ…Call Girls In Mamura Sector 66 ( Noida)Delhi Call girls
ย 
Call Girls In Pratap Nagar Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”
Call Girls In Pratap Nagar Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”Call Girls In Pratap Nagar Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”
Call Girls In Pratap Nagar Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”soniya singh
ย 
Call Girls In Sukhdev Vihar Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”
Call Girls In Sukhdev Vihar Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”Call Girls In Sukhdev Vihar Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”
Call Girls In Sukhdev Vihar Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”soniya singh
ย 
Call Girls In Model Towh Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”
Call Girls In Model Towh Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”Call Girls In Model Towh Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”
Call Girls In Model Towh Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”soniya singh
ย 
Call Now โ˜Ž 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now โ˜Ž 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.Call Now โ˜Ž 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now โ˜Ž 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.soniya singh
ย 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024APNIC
ย 
Call Girls In Defence Colony Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”
Call Girls In Defence Colony Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”Call Girls In Defence Colony Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”
Call Girls In Defence Colony Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”soniya singh
ย 
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...SUHANI PANDEY
ย 
Enjoy NightโšกCall Girls Dlf City Phase 3 Gurgaon >เผ’8448380779 Escort Service
Enjoy NightโšกCall Girls Dlf City Phase 3 Gurgaon >เผ’8448380779 Escort ServiceEnjoy NightโšกCall Girls Dlf City Phase 3 Gurgaon >เผ’8448380779 Escort Service
Enjoy NightโšกCall Girls Dlf City Phase 3 Gurgaon >เผ’8448380779 Escort ServiceDelhi Call girls
ย 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Servicegwenoracqe6
ย 
Al Barsha Night Partner +0567686026 Call Girls Dubai
Al Barsha Night Partner +0567686026 Call Girls  DubaiAl Barsha Night Partner +0567686026 Call Girls  Dubai
Al Barsha Night Partner +0567686026 Call Girls DubaiEscorts Call Girls
ย 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...tanu pandey
ย 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...SUHANI PANDEY
ย 
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...SUHANI PANDEY
ย 
Call Now โ˜Ž 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now โ˜Ž 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now โ˜Ž 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now โ˜Ž 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.soniya singh
ย 

Recently uploaded (20)

On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024
ย 
WhatsApp ๐Ÿ“ž 8448380779 โœ…Call Girls In Mamura Sector 66 ( Noida)
WhatsApp ๐Ÿ“ž 8448380779 โœ…Call Girls In Mamura Sector 66 ( Noida)WhatsApp ๐Ÿ“ž 8448380779 โœ…Call Girls In Mamura Sector 66 ( Noida)
WhatsApp ๐Ÿ“ž 8448380779 โœ…Call Girls In Mamura Sector 66 ( Noida)
ย 
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
Russian Call Girls in %(+971524965298  )#  Call Girls in DubaiRussian Call Girls in %(+971524965298  )#  Call Girls in Dubai
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
ย 
Call Girls In Pratap Nagar Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”
Call Girls In Pratap Nagar Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”Call Girls In Pratap Nagar Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”
Call Girls In Pratap Nagar Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”
ย 
Call Girls In Sukhdev Vihar Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”
Call Girls In Sukhdev Vihar Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”Call Girls In Sukhdev Vihar Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”
Call Girls In Sukhdev Vihar Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”
ย 
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
ย 
Call Girls In Model Towh Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”
Call Girls In Model Towh Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”Call Girls In Model Towh Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”
Call Girls In Model Towh Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”
ย 
Call Now โ˜Ž 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now โ˜Ž 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.Call Now โ˜Ž 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now โ˜Ž 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
ย 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
ย 
Call Girls In Defence Colony Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”
Call Girls In Defence Colony Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”Call Girls In Defence Colony Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”
Call Girls In Defence Colony Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”
ย 
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
ย 
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
ย 
Enjoy NightโšกCall Girls Dlf City Phase 3 Gurgaon >เผ’8448380779 Escort Service
Enjoy NightโšกCall Girls Dlf City Phase 3 Gurgaon >เผ’8448380779 Escort ServiceEnjoy NightโšกCall Girls Dlf City Phase 3 Gurgaon >เผ’8448380779 Escort Service
Enjoy NightโšกCall Girls Dlf City Phase 3 Gurgaon >เผ’8448380779 Escort Service
ย 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
ย 
Al Barsha Night Partner +0567686026 Call Girls Dubai
Al Barsha Night Partner +0567686026 Call Girls  DubaiAl Barsha Night Partner +0567686026 Call Girls  Dubai
Al Barsha Night Partner +0567686026 Call Girls Dubai
ย 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
ย 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
ย 
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
ย 
Low Sexy Call Girls In Mohali 9053900678 ๐ŸฅตHave Save And Good Place ๐Ÿฅต
Low Sexy Call Girls In Mohali 9053900678 ๐ŸฅตHave Save And Good Place ๐ŸฅตLow Sexy Call Girls In Mohali 9053900678 ๐ŸฅตHave Save And Good Place ๐Ÿฅต
Low Sexy Call Girls In Mohali 9053900678 ๐ŸฅตHave Save And Good Place ๐Ÿฅต
ย 
Call Now โ˜Ž 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now โ˜Ž 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now โ˜Ž 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now โ˜Ž 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
ย 

Fewd week6 slides

  • 1. FEWD - WEEK 6 WILL MYERS Freelance Front End Developer SLIDES http://www.slideshare.net/wilkom/fewd-week6-slides
  • 2. YOUR WEEKLY FEWD GITHUB REPOSITORY Use the '+' button in the top-left of GitHub Desktop (Create tab) Create a new repository called 'FEWD_Week6' Choose the [home]/FEWD folder for the local path Open this repo folder in your editor Commit the changes and publish the FEWD_Week6 repository to github.com
  • 3. YOUR WEEKLY WORKING FILES FROM ME To get the week6_working_files you should just be able to select the ga-fewd-files repository in GitHub Desktop and press 'Sync'. This should pull in this weeks folder from github.com. If you any difficulties you should just re-clone the ga-fewd- files repository. Copy the whole week6_working_files into your FEWD_Week6 repository and commit and publish to github.com
  • 4. REVIEW OF LAST WEEK'S ASSIGNMENT
  • 7. ARRAYS What if we had a collection of images that we wanted to display to the screen one at a time? How could we store all the images?
  • 8. ARRAYS An array is a list object with built in methods for things like: adding to the list removing from the list traversal of the list.
  • 9. DECLARING ARRAYS var myArr = new Array(); declaring an empty array using the Array constructor.
  • 10. DECLARING ARRAYS var myArr = [ ]; declaring an empty array using literal notation.
  • 11. DECLARING ARRAYS myArr = ['Hello', 54.3, true]; Arrays are filled with elements: i.e. myArr3 = [element, anotherElement]; Elements can contain strings, numbers, booleans, and more.
  • 12. DECLARING ARRAYS If you leave a blank spot in an array it creates a blank shelf space (undefined) placeholder.
  • 14. ARRAYS INDEXING Array elements can be fetched by their index number (starts from 0). myArr = ['Hello', , 54.3, true]; console.log(myArr[0]); //prints Hello console.log(myArr[1]); //prints undefined console.log(myArr[2]); //prints 54.3 console.log(myArr[3]); //prints true
  • 15. ARRAYS INDEXING We can insert new values into any space in the array using the positions index. myArr[1] = 'Stuff';
  • 16. ARRAYS INDEXING We can overwrite all the elements of an array simply by giving the array new values or by setting an array equal to a different array. var fruits = ['Apples', 'Oranges', 'Pears', 'Bananas']; var myArr=[1,2,3]; myArr = fruits; console.log(myArr); //prints Apples, Oranges, Pears, Bananas
  • 17. ARRAY LENGTH What if I would like to know how long my array is (how many elements)? console.log(myArr.length); //prints 4
  • 18. ARRAY METHODS The Array object has many built in methods for doing stuff with arrays. Here are two common methods: Array.push()adds an item to the end of an array var myArr = [1,2,3]; myArr.push(4); //myArr === [1,2,3,4] Array.pop()removes an item from the end of an array var myArr = [1,2,3,4]; var popped = myArr.pop(); //myArr === [1,2,3]; popped = 4;
  • 20. ITERATE OVER ARRAY Computers can repeatedly execute lines of code very quickly (in milliseconds and nanoseconds) Combined with conditions (if) computers can process large quantities of data quickly and make "intelligent" decisions based on this data. Sequentially processing a list of data and doing something with the data is one of the most common activities in programming.
  • 21. ITERATE OVER ARRAY - REPEAT LOOPS forloop: for (var i = 0; i < 5; i++) { //i runs from 0 to 4 in this loop. }; whileloop: var n = 10; while(n--){ console.log('n is', n); //n runs from 9 to 0 };
  • 22. ITERATE OVER ARRAY The Array.forEachmethod also allows you to run code using each element from the array as a value You pass an anonymous function with pre-defined arguments var fruits=["Banana","Apple","Pear"] fruits.forEach(function(element,index){ console.log(element, "is at position", index); }); elementis the item from the array indexis the item's position in the array
  • 23. MORE ON ARRAYS For many more Array methods see:โ€‹ https://developer.mozilla.org/en- US/docs/JavaScript/Reference/Global_Objects/Array
  • 25. WEATHER APPLICATION Can you build a weather application that works in the same way as your CitiPix assignment? The user inputs a temperature in Celsius This temperature gets converted to Fahrenheit and displayed on the page Change the display of an image on the page if the temperature is cold or hot (< 20 degrees Celsius or >= 20 degrees Celsius)
  • 26. ROCK PAPER SCISSORS Open week6_working_files/rock_paper_scissors
  • 28. REFACTOR Making code more efficient without changing functionality.
  • 29. REFACTOR The process of rewriting code without changing functionality To reduce or eliminate redundancy Make code easier to read Make code more maintainable
  • 30. CSS REFACTOR Remove inline styling Replace repeated styles with classes Rename classes/ids for readability Organize CSS Group by section Order by precedence (tag selectors at top, id selectors at bottom) Create classes for large CSS changes in JS Remove unnecessary css
  • 31. JS REFACTOR Use functions Use variables Use arrays Combine jQuery selectors Combine jQuery property changes into objects .css,.attr,etc Chain jQuery function calls
  • 33. SWITCH BLOCKS When you end up writing a lot if ... elsesyntax in your code (for example in the Rock Paper Scissors game) you can use a different syntax (as follows) to make your code a bit cleaner and clearer: switch(someValue){ case "value1": doThis(); break; case "value2": doThat(); break; default: doSomethingElse(); } It is important have the break;keyword at the end of each casestatement, so as to exit the switchblock correctly.
  • 34. SWITCH BLOCKS Let's refactor Rock Paper Scissors with a switchblock
  • 35. KEYWORD: "THIS" In JavaScript thisis the keyword for a context object. It is used inside a function block. You can think of the context as the owner of a function. If you write a function in the global context, then thiswill refer to the global windowobject. //written in the global window context of your JavaScript file function doSomething(){ return this; //this refers to the global window object } console.log (doSomething() === window);// returns true
  • 36. KEYWORD: "THIS" When you attach a function as an event handler to an HTML element, then the element becomes the owner of the function and so thiswill refer to the element. element.onclick = doSomething; See this link for more info on when thisrefers to an HTML element: http://www.quirksmode.org/js/this.html
  • 37. KEYWORD: "THIS" IN JQUERY jQuery uses thiswrapped in a jQuery selection, so that it can call jQuery methods directly on the selected element. If you wrap thisin jQuery - $(this)- in your handler, it will refer to the element you have selected using jQuery. See this codepen: http://codepen.io/wilkom/pen/xZjeWz
  • 38. KEYWORD: "THIS" IN JQUERY This is useful when you are applying the same event handler to a group elements and you want each element to work independently. $("p").on("click",function(e){ $(this).fadeOut(500); }); Rule of thumb (ROT): If I don't know what thing will be acted on, then I should consider using "this"
  • 39. REFACTOR USING THIS Open week6_working_files/color_scheme
  • 41. DEBUGGING Always start be defining the problem. "The image is not moving" "None of my code works"
  • 42. DEBUGGING This will tell you where to start your hunt Image not moving find the code that makes the image move None of my code works Syntax error, check console
  • 43. DEBUGGING: LEVEL 1 Check for errors (red text, aligned right) in console To access debugging console PC: CTRL+SHIFT+J Mac: COMMAND+OPTION+J Click the error The location may not be correct but is a good place to start Ex: Unbalanced brackets or parentheses
  • 44. DEBUGGING: LEVEL 2 So no red errors but not getting the right answer? Try console.log Ex: var stringOfNames=""; ["Bob","Joe"].forEach(function(element){ stringOfNames-=element+","; console.log(stringOfNames); });
  • 45. DEBUGGING: LEVEL 3 Use the debugger in Chrome Set a breakpoint Run the code Step through the code until you get to the error Variable values display on the right You can switch to the console to run code or check value of variable
  • 46. DEBUGGING: LEVEL 4 Get help! 1. Try "Your preferred search engine" search 2. Be ready to clearly articulate the problem (Write out what your problem is) 3. If nothing, ask instructor