SlideShare une entreprise Scribd logo
1  sur  31
Télécharger pour lire hors ligne
BEGINNING JAVASCRIPT
CLASS 4Javascript ~ Girl Develop It ~
WELCOME!
Girl Develop It is here to provide affordable and
accessible programs to learn software through
mentorship and hands-on instruction.
Some "rules"
We are here for you!
Every question is important
Help each other
Have fun
HTML FORMS
HTML Forms allow users to enter information
Enter a name
I like popcorn
Favorite Dinosaur
Tyrannosaurus Rex
Go!
HTML FORMS
HTML code for a form
<form action="serverSideHandler.aspx" id="about-me">
<input type = "text" id = "name" placeholder = "Enter a name"/>
<input type = "checkbox" id="popcorn" />I like popcorn
<label>Favorite Dinosaur</label>
<select id = "dinosaur">
<option value = "t-rex">Tyrannosaurus Rex</option>
<option value = "tri">Triceratops</option>
<option value = "stego">Stegosaurus</option>
<option value = "other">Other</option>
</select>
<input type = "submit" value = "Go!" style = "padding: 7px; font-size:1em"/>
</form>
VALUES FROM FORMS
You can use JavaScript to get values from a form
Or set values of a form
var name = document.getElementById('name').value;
document.write(name);
var popcorn = document.getElementById('popcorn').checked;
document.write(popcorn);
name.value = 'Another name!';
popcorn.checked = true;
FORM SUBMIT EVENT
Forms have a submit event.
The submit event fires when a user clicks on a submit
button or can be fired using the submit() method in
JavaScript.
Often, the submit event handler is used to validate
input before sending it to the server.
event.preventDefault() to prevent the form trying to
submit to a server.
function submitHandler(event) {
//Validate input values.
event.preventDefault();
}
var aboutMeForm = document.getElementById('about-me');
aboutMeForm.addEventListener('submit', submitHandler);
LET'S DEVELOP IT
Choose one of your functions made so far.
Create a form to send dynamic data to the function
when you click the button.
For example, take in the age, final age, and daily cost
for the supply calculator.
Don't forget to add parameters to your existing
functions!
<button id="calculate-supply" type="submit">Calculate Supply</button>
<form id="supply-calculator">
<label for="age">Age</label><input type="text" id="age" />
<label for="maxAge">Max Age</label><input type="text" id="maxAge" />
<label for="cost">Cost</label><input type="text" id="cost" />
</form>
var ageInput = document.getElementById('age');
var age = ageInput.value;
LET'S ANSWER IT (SUPPLY CALCULATOR)
<form id="supply-calculator">
<label for="age">Age:</label><input type="text" id="age" />
<label for="maxAge">Max Age:</label><input type="text" id="maxAge" />
<label for="cost">Cost:</label><input type="text" id="cost" />
</form>
document.addEventListener("DOMContentLoaded", function() {
var form = document.getElementById('supply-calculator');
form.addEventListener('submit', getFormValues); });
function getFormValues(event) {
var ageInput = document.getElementById('age');
var age = ageInput.value;
var maxAgeInput = document.getElementById('maxAge');
var maxAge = maxAgeInput.value;
var costInput = document.getElementById('cost');
var cost = costInput.value;
calculate(age, maxAge, dailyCost);
event.preventDefault();
}
function calculate(age, maxAge, dailyCost) { ... }
WARNING
The following few slides have lots of acronyms and
jargon.
On behalf of developers everywhere, we apologize
WHAT IS AN API?
Application Programming Interface
Data structure and rules for accessing an application
How we can access information from sites that are
not our own (GitHub, Twitter, Meetup, Facebook,
Foursquare)
Primary role: a channel for applications to work
together
WHERE DO I LEARN ABOUT AN API?
All (good) APIs have documentation
GitHub ( )
Facebook ( )
Twitter ( )
Meetup ( )
FourSquare ( )
http://developer.github.com/
https://developers.facebook.com/
https://dev.twitter.com/
http://www.meetup.com/meetup_api/
https://developer.foursquare.com/
ACCESSING APIS
Most APIs require an API Key
A what?
API Key or Developer Key is a way for an API to
identify you
More secure for an API (Know who is using their API)
More secure for you -- people can't pretend to be
your website
Not all APIs require a key!
The APIs we'll be using today (GitHub) don't require
a key.
WHAT IS AJAX?
Asynchronous JavaScript and XML
Method to communicate to a server or API
Asynchronous means:
I ask Twitter for all the tweets ever!
That will take a while
My whole website could be locked up while I wait!
Or, my call can be 'asynchronous' and my website
will just listen for Twitter's response with one ear,
but go about normal business until the response
arrives.
Requests and results can be in JavaScript or XML
WHAT IS REST?
Representational State Transfer
REST is a way to ask an API for information by using
a URL.
REST Urls are created with the following syntax:
http://ApiSite.com/method?
parameter=value&parameter=value
Method -- what you want from the API. Defined by
API documentations
Parameter -- a type of filter or restraint. Defined by
API documentations
Value -- value for parameter. Defined by you!
WHAT IS JSON?
JavaScript Object Notation
Format for data returned from APIs
You've seen it before!
JavaScript objects
{
"status": "active",
"title": "Instructor",
"bio": "Hi, everybody! I'm an instructor for GDI. My teaching background spans from high school to the present. M
y professional background spans back-end, front-end, testing, and technical writing.",
"name": "Dallas Tester",
"group": {
"id": 7208692,
"name": "Girl Develop It Seattle",
"urlname": "Girl-Develop-It-Seattle",
"who": "Nerdettes"
}
}
MAKING AJAX CALLS WITH JAVASCRIPT
Use the XMLHttpRequest object built in to JavaScript
We're using the onreadystatechange event handler to
wait until the request is finished (readyState === 4) and
then log the JSON result to the console.
var serverRequest = new XMLHttpRequest();
serverRequest.onreadystatechange = function() {
if(serverRequest.readyState === 4) {
console.log(serverRequest.responseText);
}
}
serverRequest.open('GET', 'URLToEndPoint', true);
serverRequest.send();
LET'S DEVELOP IT
Let's make a call to GitHub's API.
We will get all of the events for the Girl Develop It
organization.
Your API is here:
https://api.github.com/orgs/girldevelopit/events
var serverRequest = new XMLHttpRequest();
serverRequest.onreadystatechange = function() {
if(serverRequest.readyState === 4) {
console.log(serverRequest.responseText);
}
}
serverRequest.open('GET', 'URL', true);
serverRequest.send();
LET'S ANSWER IT!
var serverRequest = new XMLHttpRequest();
serverRequest.onreadystatechange = function() {
if(serverRequest.readyState === 4) {
console.log(serverRequest.responseText);
}
}
serverRequest.open('GET', 'https://api.github.com/orgs/girldevelopit/events', true);
serverRequest.send();
[
{
"id": "1837010532",
"type": "WatchEvent",
"actor": {
"id": 3051672,
"login": "celiala",
"url": "https://api.github.com/users/celiala",
"avatar_url": "https://2.gravatar.com/avatar/d22540938c49eba7da81d45fa1f0f245?d=https%3A%2…kamai.net%2Fasse
ts.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png"
}
...
}
]
WHAT IS A LIBRARY?
Software libraries contain functions (not books).
When you include a library, you can use all the
functions in that library
That means: you get to take advantage of other
people's experience!
And... Save time!
WHAT IS JQUERY?
jQuery is a library of JavaScript functions.
It contains many functions to help simplify your
JavaScript programming, including:
HTML element selection & manipulation
CSS manipulation
HTML events
Calling APIs
WHY USE JQUERY?
The most popular JavaScript library
jQuery empowers you to "write less, do more."
Great
Used by nearly 20 million websites
documentation and tutorials
INCLUDING JQUERY
Two ways to include jQuery on your page:
Download the library, store it locally:
Include the the live library:
Note: live code can change so be aware when deciding
on how you include the code.
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
WHAT CAN JQUERY DO FOR ME?
Remember document.getElementById() and
documet.getElementsByTagName()?
jQuery makes it this easy:
Element name (div, p)
ID name (#mainpicture, #results)
Class name (.result, .picture)
var divs = $('div'); // All divs on page
var img = $('#mainpicture'); //img with id mainpicture
var images = $('.picture'); //All images with class picture
WHAT CAN JQUERY DO FOR ME?
Get and set attributes easily:
Get and set CSS properties:
Create elements:
Get and set the value (replaces innerHTML)
var img = $('#mainpicture');
var imageUrl = img.attr('src');
img.attr('src', 'http://www.website.com/newImage.png');
var imageWidth = img.css('width');
img.css('width', '200px');
var newDiv = $('<div></div>');
var div = $('#results');
var divHTML = div.html();
div.html('<b>This is new HTML!</b>');
WHAT CAN JQUERY DO FOR ME?
Append and prepend text (no more createTextNode):
Simplify adding events...
...and the DOMContentLoaded event:
Data access is easy, too:
var div = $('#results');
div.append('This is new text at the end!');
div.prepend('This is new text at the beginning!');
var button = $('#calculate-button');
button.click(function() { ... });
$(document).ready(function() { ... });
$.ajax({
url: 'https://api.github.com...',
success: function(data) { //Event handler here }
});
Along with a LOT more!
LET'S DEVELOP IT
Include the jQuery library on your page. jquery.com
has a nice shortcut called Quick Access at the bottom
of every page.
Update your previous code to use $.ajax for the
GitHub API call.
jQuery returns an array of objects from this particular
API. Utilize looping to get objects and output their id
property.
Feel free to play around with the other functionality of
jQuery.
$(document).ready(function() {
$.ajax({
url: 'https://api.github.com/orgs/girldevelopit/events',
success: function(data) {
//Do something with the data...
}
});
});
LET'S ANSWER IT
$(document).ready(function() {
$.ajax({
url: 'https://api.github.com/orgs/girldevelopit/events',
success: function(data) {
for(var i = 0; i < data.length; i++) {
console.log(data[i].id);
} //end for loop
} //end success function
}); //end AJAX call
}); //end document ready call
QUESTIONS?
?
GDI Seattle - Intro to JavaScript Class 4

Contenu connexe

Tendances

Jquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsJquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsEPAM Systems
 
jQuery Features to Avoid
jQuery Features to AvoidjQuery Features to Avoid
jQuery Features to Avoiddmethvin
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginningAnis Ahmad
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery FundamentalsGil Fink
 
A Short Introduction To jQuery
A Short Introduction To jQueryA Short Introduction To jQuery
A Short Introduction To jQuerySudar Muthu
 
User Interface Development with jQuery
User Interface Development with jQueryUser Interface Development with jQuery
User Interface Development with jQuerycolinbdclark
 
Nothing Hard Baked: Designing the Inclusive Web
Nothing Hard Baked: Designing the Inclusive WebNothing Hard Baked: Designing the Inclusive Web
Nothing Hard Baked: Designing the Inclusive Webcolinbdclark
 
Stack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for DevelopersStack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for DevelopersJonathan Sharp
 
jQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingjQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingDoug Neiner
 

Tendances (20)

Jquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsJquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript Basics
 
jQuery Features to Avoid
jQuery Features to AvoidjQuery Features to Avoid
jQuery Features to Avoid
 
jQuery
jQueryjQuery
jQuery
 
Jquery
JqueryJquery
Jquery
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
J query training
J query trainingJ query training
J query training
 
22 j query1
22 j query122 j query1
22 j query1
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
jQuery Introduction
jQuery IntroductionjQuery Introduction
jQuery Introduction
 
jQuery
jQueryjQuery
jQuery
 
Learn css3
Learn css3Learn css3
Learn css3
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
 
A Short Introduction To jQuery
A Short Introduction To jQueryA Short Introduction To jQuery
A Short Introduction To jQuery
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
User Interface Development with jQuery
User Interface Development with jQueryUser Interface Development with jQuery
User Interface Development with jQuery
 
Nothing Hard Baked: Designing the Inclusive Web
Nothing Hard Baked: Designing the Inclusive WebNothing Hard Baked: Designing the Inclusive Web
Nothing Hard Baked: Designing the Inclusive Web
 
Stack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for DevelopersStack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for Developers
 
jQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingjQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and Bling
 
Jquery introduction
Jquery introductionJquery introduction
Jquery introduction
 

Similaire à GDI Seattle - Intro to JavaScript Class 4

Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...
Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...
Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...Ayes Chinmay
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentationguest5d87aa6
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoRob Bontekoe
 
Javascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & TricksJavascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & TricksHjörtur Hilmarsson
 
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
How I Learned to Stop Worrying and Love jQuery (Jan 2013)How I Learned to Stop Worrying and Love jQuery (Jan 2013)
How I Learned to Stop Worrying and Love jQuery (Jan 2013)David Giard
 
jQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends ForeverjQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends Foreverstephskardal
 
Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Thinqloud
 
Summer - The HTML5 Library for Java and Scala
Summer - The HTML5 Library for Java and ScalaSummer - The HTML5 Library for Java and Scala
Summer - The HTML5 Library for Java and Scalarostislav
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)Doris Chen
 

Similaire à GDI Seattle - Intro to JavaScript Class 4 (20)

Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...
Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...
Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...
 
Jquery fundamentals
Jquery fundamentalsJquery fundamentals
Jquery fundamentals
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentation
 
Jquery
JqueryJquery
Jquery
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" Domino
 
前端概述
前端概述前端概述
前端概述
 
Javascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & TricksJavascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & Tricks
 
Broadleaf Presents Thymeleaf
Broadleaf Presents ThymeleafBroadleaf Presents Thymeleaf
Broadleaf Presents Thymeleaf
 
Jquery
JqueryJquery
Jquery
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
J Query Public
J Query PublicJ Query Public
J Query Public
 
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
How I Learned to Stop Worrying and Love jQuery (Jan 2013)How I Learned to Stop Worrying and Love jQuery (Jan 2013)
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
 
jQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends ForeverjQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends Forever
 
Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...
 
Summer - The HTML5 Library for Java and Scala
Summer - The HTML5 Library for Java and ScalaSummer - The HTML5 Library for Java and Scala
Summer - The HTML5 Library for Java and Scala
 
Wt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technologyWt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technology
 
Wt unit 2 ppts client side technology
Wt unit 2 ppts client side technologyWt unit 2 ppts client side technology
Wt unit 2 ppts client side technology
 
Jquery Basics
Jquery BasicsJquery Basics
Jquery Basics
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
 
Html5 For Jjugccc2009fall
Html5 For Jjugccc2009fallHtml5 For Jjugccc2009fall
Html5 For Jjugccc2009fall
 

Plus de Heather Rock

GDI Seattle - Web Accessibility Class 1
GDI Seattle - Web Accessibility Class 1GDI Seattle - Web Accessibility Class 1
GDI Seattle - Web Accessibility Class 1Heather Rock
 
GDI Seattle - Intro to JavaScript Class 2
GDI Seattle - Intro to JavaScript Class 2GDI Seattle - Intro to JavaScript Class 2
GDI Seattle - Intro to JavaScript Class 2Heather Rock
 
GDI Seattle - Intro to JavaScript Class 1
GDI Seattle - Intro to JavaScript Class 1GDI Seattle - Intro to JavaScript Class 1
GDI Seattle - Intro to JavaScript Class 1Heather Rock
 
GDI Seattle Intro to HTML and CSS - Class 4
GDI Seattle Intro to HTML and CSS - Class 4GDI Seattle Intro to HTML and CSS - Class 4
GDI Seattle Intro to HTML and CSS - Class 4Heather Rock
 
GDI Seattle - Intermediate HTML and CSS Class 3 Slides
GDI Seattle - Intermediate HTML and CSS Class 3 SlidesGDI Seattle - Intermediate HTML and CSS Class 3 Slides
GDI Seattle - Intermediate HTML and CSS Class 3 SlidesHeather Rock
 
GDI Seattle Intro to HTML and CSS - Class 3
GDI Seattle Intro to HTML and CSS - Class 3GDI Seattle Intro to HTML and CSS - Class 3
GDI Seattle Intro to HTML and CSS - Class 3Heather Rock
 
Intro to HTML and CSS - Class 2 Slides
Intro to HTML and CSS - Class 2 SlidesIntro to HTML and CSS - Class 2 Slides
Intro to HTML and CSS - Class 2 SlidesHeather Rock
 
GDI Seattle Intermediate HTML and CSS Class 1
GDI Seattle Intermediate HTML and CSS Class 1GDI Seattle Intermediate HTML and CSS Class 1
GDI Seattle Intermediate HTML and CSS Class 1Heather Rock
 
GDI Seattle Intro to HTML and CSS - Class 1
GDI Seattle Intro to HTML and CSS - Class 1GDI Seattle Intro to HTML and CSS - Class 1
GDI Seattle Intro to HTML and CSS - Class 1Heather Rock
 

Plus de Heather Rock (9)

GDI Seattle - Web Accessibility Class 1
GDI Seattle - Web Accessibility Class 1GDI Seattle - Web Accessibility Class 1
GDI Seattle - Web Accessibility Class 1
 
GDI Seattle - Intro to JavaScript Class 2
GDI Seattle - Intro to JavaScript Class 2GDI Seattle - Intro to JavaScript Class 2
GDI Seattle - Intro to JavaScript Class 2
 
GDI Seattle - Intro to JavaScript Class 1
GDI Seattle - Intro to JavaScript Class 1GDI Seattle - Intro to JavaScript Class 1
GDI Seattle - Intro to JavaScript Class 1
 
GDI Seattle Intro to HTML and CSS - Class 4
GDI Seattle Intro to HTML and CSS - Class 4GDI Seattle Intro to HTML and CSS - Class 4
GDI Seattle Intro to HTML and CSS - Class 4
 
GDI Seattle - Intermediate HTML and CSS Class 3 Slides
GDI Seattle - Intermediate HTML and CSS Class 3 SlidesGDI Seattle - Intermediate HTML and CSS Class 3 Slides
GDI Seattle - Intermediate HTML and CSS Class 3 Slides
 
GDI Seattle Intro to HTML and CSS - Class 3
GDI Seattle Intro to HTML and CSS - Class 3GDI Seattle Intro to HTML and CSS - Class 3
GDI Seattle Intro to HTML and CSS - Class 3
 
Intro to HTML and CSS - Class 2 Slides
Intro to HTML and CSS - Class 2 SlidesIntro to HTML and CSS - Class 2 Slides
Intro to HTML and CSS - Class 2 Slides
 
GDI Seattle Intermediate HTML and CSS Class 1
GDI Seattle Intermediate HTML and CSS Class 1GDI Seattle Intermediate HTML and CSS Class 1
GDI Seattle Intermediate HTML and CSS Class 1
 
GDI Seattle Intro to HTML and CSS - Class 1
GDI Seattle Intro to HTML and CSS - Class 1GDI Seattle Intro to HTML and CSS - Class 1
GDI Seattle Intro to HTML and CSS - Class 1
 

Dernier

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 

Dernier (20)

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 

GDI Seattle - Intro to JavaScript Class 4

  • 2.
  • 3. WELCOME! Girl Develop It is here to provide affordable and accessible programs to learn software through mentorship and hands-on instruction. Some "rules" We are here for you! Every question is important Help each other Have fun
  • 4. HTML FORMS HTML Forms allow users to enter information Enter a name I like popcorn Favorite Dinosaur Tyrannosaurus Rex Go!
  • 5. HTML FORMS HTML code for a form <form action="serverSideHandler.aspx" id="about-me"> <input type = "text" id = "name" placeholder = "Enter a name"/> <input type = "checkbox" id="popcorn" />I like popcorn <label>Favorite Dinosaur</label> <select id = "dinosaur"> <option value = "t-rex">Tyrannosaurus Rex</option> <option value = "tri">Triceratops</option> <option value = "stego">Stegosaurus</option> <option value = "other">Other</option> </select> <input type = "submit" value = "Go!" style = "padding: 7px; font-size:1em"/> </form>
  • 6. VALUES FROM FORMS You can use JavaScript to get values from a form Or set values of a form var name = document.getElementById('name').value; document.write(name); var popcorn = document.getElementById('popcorn').checked; document.write(popcorn); name.value = 'Another name!'; popcorn.checked = true;
  • 7. FORM SUBMIT EVENT Forms have a submit event. The submit event fires when a user clicks on a submit button or can be fired using the submit() method in JavaScript. Often, the submit event handler is used to validate input before sending it to the server. event.preventDefault() to prevent the form trying to submit to a server. function submitHandler(event) { //Validate input values. event.preventDefault(); } var aboutMeForm = document.getElementById('about-me'); aboutMeForm.addEventListener('submit', submitHandler);
  • 8. LET'S DEVELOP IT Choose one of your functions made so far. Create a form to send dynamic data to the function when you click the button. For example, take in the age, final age, and daily cost for the supply calculator. Don't forget to add parameters to your existing functions! <button id="calculate-supply" type="submit">Calculate Supply</button> <form id="supply-calculator"> <label for="age">Age</label><input type="text" id="age" /> <label for="maxAge">Max Age</label><input type="text" id="maxAge" /> <label for="cost">Cost</label><input type="text" id="cost" /> </form> var ageInput = document.getElementById('age'); var age = ageInput.value;
  • 9. LET'S ANSWER IT (SUPPLY CALCULATOR) <form id="supply-calculator"> <label for="age">Age:</label><input type="text" id="age" /> <label for="maxAge">Max Age:</label><input type="text" id="maxAge" /> <label for="cost">Cost:</label><input type="text" id="cost" /> </form> document.addEventListener("DOMContentLoaded", function() { var form = document.getElementById('supply-calculator'); form.addEventListener('submit', getFormValues); }); function getFormValues(event) { var ageInput = document.getElementById('age'); var age = ageInput.value; var maxAgeInput = document.getElementById('maxAge'); var maxAge = maxAgeInput.value; var costInput = document.getElementById('cost'); var cost = costInput.value; calculate(age, maxAge, dailyCost); event.preventDefault(); } function calculate(age, maxAge, dailyCost) { ... }
  • 10. WARNING The following few slides have lots of acronyms and jargon. On behalf of developers everywhere, we apologize
  • 11. WHAT IS AN API? Application Programming Interface Data structure and rules for accessing an application How we can access information from sites that are not our own (GitHub, Twitter, Meetup, Facebook, Foursquare) Primary role: a channel for applications to work together
  • 12. WHERE DO I LEARN ABOUT AN API? All (good) APIs have documentation GitHub ( ) Facebook ( ) Twitter ( ) Meetup ( ) FourSquare ( ) http://developer.github.com/ https://developers.facebook.com/ https://dev.twitter.com/ http://www.meetup.com/meetup_api/ https://developer.foursquare.com/
  • 13. ACCESSING APIS Most APIs require an API Key A what? API Key or Developer Key is a way for an API to identify you More secure for an API (Know who is using their API) More secure for you -- people can't pretend to be your website Not all APIs require a key! The APIs we'll be using today (GitHub) don't require a key.
  • 14. WHAT IS AJAX? Asynchronous JavaScript and XML Method to communicate to a server or API Asynchronous means: I ask Twitter for all the tweets ever! That will take a while My whole website could be locked up while I wait! Or, my call can be 'asynchronous' and my website will just listen for Twitter's response with one ear, but go about normal business until the response arrives. Requests and results can be in JavaScript or XML
  • 15. WHAT IS REST? Representational State Transfer REST is a way to ask an API for information by using a URL. REST Urls are created with the following syntax: http://ApiSite.com/method? parameter=value&parameter=value Method -- what you want from the API. Defined by API documentations Parameter -- a type of filter or restraint. Defined by API documentations Value -- value for parameter. Defined by you!
  • 16. WHAT IS JSON? JavaScript Object Notation Format for data returned from APIs You've seen it before! JavaScript objects { "status": "active", "title": "Instructor", "bio": "Hi, everybody! I'm an instructor for GDI. My teaching background spans from high school to the present. M y professional background spans back-end, front-end, testing, and technical writing.", "name": "Dallas Tester", "group": { "id": 7208692, "name": "Girl Develop It Seattle", "urlname": "Girl-Develop-It-Seattle", "who": "Nerdettes" } }
  • 17. MAKING AJAX CALLS WITH JAVASCRIPT Use the XMLHttpRequest object built in to JavaScript We're using the onreadystatechange event handler to wait until the request is finished (readyState === 4) and then log the JSON result to the console. var serverRequest = new XMLHttpRequest(); serverRequest.onreadystatechange = function() { if(serverRequest.readyState === 4) { console.log(serverRequest.responseText); } } serverRequest.open('GET', 'URLToEndPoint', true); serverRequest.send();
  • 18. LET'S DEVELOP IT Let's make a call to GitHub's API. We will get all of the events for the Girl Develop It organization. Your API is here: https://api.github.com/orgs/girldevelopit/events var serverRequest = new XMLHttpRequest(); serverRequest.onreadystatechange = function() { if(serverRequest.readyState === 4) { console.log(serverRequest.responseText); } } serverRequest.open('GET', 'URL', true); serverRequest.send();
  • 19. LET'S ANSWER IT! var serverRequest = new XMLHttpRequest(); serverRequest.onreadystatechange = function() { if(serverRequest.readyState === 4) { console.log(serverRequest.responseText); } } serverRequest.open('GET', 'https://api.github.com/orgs/girldevelopit/events', true); serverRequest.send(); [ { "id": "1837010532", "type": "WatchEvent", "actor": { "id": 3051672, "login": "celiala", "url": "https://api.github.com/users/celiala", "avatar_url": "https://2.gravatar.com/avatar/d22540938c49eba7da81d45fa1f0f245?d=https%3A%2…kamai.net%2Fasse ts.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png" } ... } ]
  • 20. WHAT IS A LIBRARY? Software libraries contain functions (not books). When you include a library, you can use all the functions in that library That means: you get to take advantage of other people's experience! And... Save time!
  • 21. WHAT IS JQUERY? jQuery is a library of JavaScript functions. It contains many functions to help simplify your JavaScript programming, including: HTML element selection & manipulation CSS manipulation HTML events Calling APIs
  • 22. WHY USE JQUERY? The most popular JavaScript library jQuery empowers you to "write less, do more." Great Used by nearly 20 million websites documentation and tutorials
  • 23. INCLUDING JQUERY Two ways to include jQuery on your page: Download the library, store it locally: Include the the live library: Note: live code can change so be aware when deciding on how you include the code. <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  • 24. WHAT CAN JQUERY DO FOR ME? Remember document.getElementById() and documet.getElementsByTagName()? jQuery makes it this easy: Element name (div, p) ID name (#mainpicture, #results) Class name (.result, .picture) var divs = $('div'); // All divs on page var img = $('#mainpicture'); //img with id mainpicture var images = $('.picture'); //All images with class picture
  • 25. WHAT CAN JQUERY DO FOR ME? Get and set attributes easily: Get and set CSS properties: Create elements: Get and set the value (replaces innerHTML) var img = $('#mainpicture'); var imageUrl = img.attr('src'); img.attr('src', 'http://www.website.com/newImage.png'); var imageWidth = img.css('width'); img.css('width', '200px'); var newDiv = $('<div></div>'); var div = $('#results'); var divHTML = div.html(); div.html('<b>This is new HTML!</b>');
  • 26. WHAT CAN JQUERY DO FOR ME? Append and prepend text (no more createTextNode): Simplify adding events... ...and the DOMContentLoaded event: Data access is easy, too: var div = $('#results'); div.append('This is new text at the end!'); div.prepend('This is new text at the beginning!'); var button = $('#calculate-button'); button.click(function() { ... }); $(document).ready(function() { ... }); $.ajax({ url: 'https://api.github.com...', success: function(data) { //Event handler here } }); Along with a LOT more!
  • 27. LET'S DEVELOP IT Include the jQuery library on your page. jquery.com has a nice shortcut called Quick Access at the bottom of every page. Update your previous code to use $.ajax for the GitHub API call. jQuery returns an array of objects from this particular API. Utilize looping to get objects and output their id property. Feel free to play around with the other functionality of jQuery. $(document).ready(function() { $.ajax({ url: 'https://api.github.com/orgs/girldevelopit/events', success: function(data) { //Do something with the data... } }); });
  • 28. LET'S ANSWER IT $(document).ready(function() { $.ajax({ url: 'https://api.github.com/orgs/girldevelopit/events', success: function(data) { for(var i = 0; i < data.length; i++) { console.log(data[i].id); } //end for loop } //end success function }); //end AJAX call }); //end document ready call
  • 30. ?