SlideShare a Scribd company logo
JavaScript 101
Review from Codecademy exercises
Parts 1–12
http://www.codecademy.com/tracks/javascript
Comparison
JavaScript

Python

var animal =
"elephant"
animal.length
8
console.log(animal)
elephant
2 + 3 * 5
17
// a comment

animal = "elephant"
len(animal)
8
print animal
elephant
2 + 3 * 5
17
# a comment
Comparison
JavaScript

Python

function myfunction(a, b) {
var answer = a + b;
return answer;
}
console.log(myfunction(3, 5));
8

def myfunction(a, b):
answer = a + b
return answer
print (myfunction(3, 5))
8

var myfunction = function(a, b) {
var answer = a + b;
return answer;
}
console.log(myfunction(3, 5));
8

also JavaScript
Alert, Confirm, Prompt
An alert dialog box gives a message
to the user. It only allows the user to
click OK.
A confirm dialog box allows the user
to choose between OK and Cancel. So
the text should ask a question, and
clicking OK should cause something
to happen.

A prompt dialog box allows the user
to type something and click OK, or
the user may cancel to close the
dialog.
Alert, Confirm, Prompt

We will do an exercise
with these later.
Booleans: Comparison
JavaScript

Python

10 > 3
true
10 < 3
false

10 > 3
True
10 < 3
False

Note that case is significant in JavaScript (just as it is in Python).
The Boolean values in Python must be uppercase.
In JavaScript, the Boolean values must be lowercase.
If–Else
JavaScript

Python

if (x == y) {
console.log("They are
equal.");
}
else if (x > y) {
console.log("x is
more.");
} else {
console.log("x is
less.");
}

if (x == y):
print "They are equal."
elif (x > y):
print "x is more."
else:
print "x is less."
For Loop
JavaScript

Python

for ( i = 0; i < 10; i++ )
{
console.log(i);
}

for i in range(0, 10):
print i

// this will print the
numbers from 0 through 9

# this will print the
numbers from 0 through 9
For Loop (2)
Python

JavaScript
While Loop
JavaScript

Python

var n = 0;
while (n < 3) {
console.log("Looping.");
n++;
}

n = 0
while (n < 3):
print "Looping."
n += 1

Looping.
Looping.
Looping.

Looping.
Looping.
Looping.
“Incrementing”
JavaScript

i++ is the same as i = i + 1
i-- is the same as i = i - 1
Python

i += 1 is the same as i = i + 1
i -= 1 is the same as i = i - 1
Extracting a substring
JavaScript

Python

var mystring = "the
word swagger"

mystring = "the word
swagger"

console.log(mystring.s
ubstring(9,13));

print mystring[9:13]
swag

swag
The switch statement
switch (//Some expression) {
case 'option1':
// Do something
break;
case 'option2':
// Do something else
break;
default:
// Do yet another thing
break;
}
Switch statement example
switch (album) {
case "asbury":
songfile = "clips/spiritinthenight.mp3";
track = "Spirit in the Night";
album = "Greetings from Asbury Park";
break;
case "wild":
songfile = "clips/fourth.mp3";
track = "4th of July, Asbury Park (Sandy)";
album = "The Wild, the Innocent, and the E Street Shuffle";
break;
case "borntorun":
songfile = "clips/thunderroad.mp3";
track = "Thunder Road";
album = "Born to Run";
break;
. . . . . . . . . .
};
Arrays (Lists)
JavaScript
var mylist = ["red", "white", "blue"];
console.log(mylist[2]);
blue
Python
mylist = ["red", "white", "blue"]
print mylist[2]
blue
Math.random()
If we declare a variable and make it equal to
Math.random(), that variable will equal a
number between 0 and 1.

Note: In JavaScript, the capital M in all Math
methods is significant. No lowercase!
Note that if you use
Math.random() to create the
value of a variable, that value
will not change randomly.

But if you run Math.random()
again and again, it will generate
a new number between 0 and 1
each time.

To use the JavaScript console in Chrome
(shown here), open the View menu >
Developer > JavaScript Console
What is happening here?
What would this code be
good for?
(Think about games.)
Note: Math.floor()
rounds a number down to the
nearest integer. It
conveniently cuts off the
decimal places. We add 1
because otherwise our
numbers would go from
0 to 5. By adding 1, they
range from 1 to 6 instead.
Guessing a number
• In-class assignment: Create a little game with
an HTML page, a confirm dialog box and
JavaScript.
• Your game will use Math.Random() to pick a
number between 1 and … ? (You choose.)
• Then the user has to guess the number, by
typing it into the confirm dialog.
• A new alert box will open and tell the user if
the guess is right or wrong.
Alert, Confirm, Prompt

Download this:
https://github.com/maclo
o/javascript_beginners
JavaScript 101
Review from Codecademy exercises
Parts 1–12
http://www.codecademy.com/tracks/javascript
Ad

More Related Content

What's hot (20)

For Loop
For LoopFor Loop
For Loop
Ghaffar Khan
 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshare
Gagan Deep
 
C++ control loops
C++ control loopsC++ control loops
C++ control loops
pratikborsadiya
 
C++ TUTORIAL 2
C++ TUTORIAL 2C++ TUTORIAL 2
C++ TUTORIAL 2
Farhan Ab Rahman
 
Iterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingIterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop working
Neeru Mittal
 
please sir i want to comments of every code what i do in eachline . in this w...
please sir i want to comments of every code what i do in eachline . in this w...please sir i want to comments of every code what i do in eachline . in this w...
please sir i want to comments of every code what i do in eachline . in this w...
hwbloom27
 
Cin and cout
Cin and coutCin and cout
Cin and cout
Lovely Professional University
 
Lecture 7- Operators and Expressions
Lecture 7- Operators and Expressions Lecture 7- Operators and Expressions
Lecture 7- Operators and Expressions
Md. Imran Hossain Showrov
 
Test driven development
Test driven developmentTest driven development
Test driven development
Suresh Thammishetty
 
Web programming[10]
Web programming[10]Web programming[10]
Web programming[10]
Muhammad Awaluddin
 
Loops in java script
Loops in java scriptLoops in java script
Loops in java script
Ravi Bhadauria
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
Mohammed Khan
 
Nested loops
Nested loopsNested loops
Nested loops
Adnan Ferdous Ahmed
 
Nesting of for loops using C++
Nesting of for loops using C++Nesting of for loops using C++
Nesting of for loops using C++
prashant_sainii
 
The Ring programming language version 1.5.3 book - Part 188 of 194
The Ring programming language version 1.5.3 book - Part 188 of 194The Ring programming language version 1.5.3 book - Part 188 of 194
The Ring programming language version 1.5.3 book - Part 188 of 194
Mahmoud Samir Fayed
 
Loops in c
Loops in cLoops in c
Loops in c
baabtra.com - No. 1 supplier of quality freshers
 
Lập Trình VBA For Excel Tại Biên Hòa
Lập Trình VBA For Excel Tại Biên HòaLập Trình VBA For Excel Tại Biên Hòa
Lập Trình VBA For Excel Tại Biên Hòa
Trần Đình Ngọc
 
Fundamentals of programming finals.ajang
Fundamentals of programming finals.ajangFundamentals of programming finals.ajang
Fundamentals of programming finals.ajang
Jaricka Angelyd Marquez
 
Ternary operator
Ternary operatorTernary operator
Ternary operator
Hitesh Kumar
 
The Ring programming language version 1.4 book - Part 29 of 30
The Ring programming language version 1.4 book - Part 29 of 30The Ring programming language version 1.4 book - Part 29 of 30
The Ring programming language version 1.4 book - Part 29 of 30
Mahmoud Samir Fayed
 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshare
Gagan Deep
 
Iterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingIterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop working
Neeru Mittal
 
please sir i want to comments of every code what i do in eachline . in this w...
please sir i want to comments of every code what i do in eachline . in this w...please sir i want to comments of every code what i do in eachline . in this w...
please sir i want to comments of every code what i do in eachline . in this w...
hwbloom27
 
Nesting of for loops using C++
Nesting of for loops using C++Nesting of for loops using C++
Nesting of for loops using C++
prashant_sainii
 
The Ring programming language version 1.5.3 book - Part 188 of 194
The Ring programming language version 1.5.3 book - Part 188 of 194The Ring programming language version 1.5.3 book - Part 188 of 194
The Ring programming language version 1.5.3 book - Part 188 of 194
Mahmoud Samir Fayed
 
Lập Trình VBA For Excel Tại Biên Hòa
Lập Trình VBA For Excel Tại Biên HòaLập Trình VBA For Excel Tại Biên Hòa
Lập Trình VBA For Excel Tại Biên Hòa
Trần Đình Ngọc
 
Fundamentals of programming finals.ajang
Fundamentals of programming finals.ajangFundamentals of programming finals.ajang
Fundamentals of programming finals.ajang
Jaricka Angelyd Marquez
 
The Ring programming language version 1.4 book - Part 29 of 30
The Ring programming language version 1.4 book - Part 29 of 30The Ring programming language version 1.4 book - Part 29 of 30
The Ring programming language version 1.4 book - Part 29 of 30
Mahmoud Samir Fayed
 

Viewers also liked (20)

Beginning jQuery
Beginning jQueryBeginning jQuery
Beginning jQuery
Mindy McAdams
 
The JavaScript Programming Primer
The JavaScript  Programming PrimerThe JavaScript  Programming Primer
The JavaScript Programming Primer
Mike Wilcox
 
Fabrication and Performance Analysis of Downdraft Biomass Gasifier Using Suga...
Fabrication and Performance Analysis of Downdraft Biomass Gasifier Using Suga...Fabrication and Performance Analysis of Downdraft Biomass Gasifier Using Suga...
Fabrication and Performance Analysis of Downdraft Biomass Gasifier Using Suga...
IJSRD
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
Raghavan Mohan
 
Introduction to web programming with JavaScript
Introduction to web programming with JavaScriptIntroduction to web programming with JavaScript
Introduction to web programming with JavaScript
T11 Sessions
 
Paris Web - Javascript as a programming language
Paris Web - Javascript as a programming languageParis Web - Javascript as a programming language
Paris Web - Javascript as a programming language
Marco Cedaro
 
Reactive Programming with JavaScript
Reactive Programming with JavaScriptReactive Programming with JavaScript
Reactive Programming with JavaScript
Codemotion
 
Javascript Tutorial
Javascript TutorialJavascript Tutorial
Javascript Tutorial
Kang-min Liu
 
Introduction to JavaScript Programming
Introduction to JavaScript ProgrammingIntroduction to JavaScript Programming
Introduction to JavaScript Programming
Collaboration Technologies
 
Functional Programming in JavaScript
Functional Programming in JavaScriptFunctional Programming in JavaScript
Functional Programming in JavaScript
Troy Miles
 
Biomass gasifier pune
Biomass gasifier  puneBiomass gasifier  pune
Biomass gasifier pune
road2ideas
 
Downdraft biomass gasification: experimental investigation and aspen plus sim...
Downdraft biomass gasification: experimental investigation and aspen plus sim...Downdraft biomass gasification: experimental investigation and aspen plus sim...
Downdraft biomass gasification: experimental investigation and aspen plus sim...
Antonio Geraldo de Paula Oliveira
 
Biomass Gasification presentation
Biomass Gasification presentationBiomass Gasification presentation
Biomass Gasification presentation
Pritish Shardul
 
Bio Mass Gasifier
Bio Mass GasifierBio Mass Gasifier
Bio Mass Gasifier
Rochester Institute of Technology
 
Biomass Gasification
Biomass GasificationBiomass Gasification
Biomass Gasification
Er Soumyabrata Basak
 
Biomass heat and power - gasification CHP with universal biomass gasifier
Biomass heat and power - gasification CHP with universal biomass gasifierBiomass heat and power - gasification CHP with universal biomass gasifier
Biomass heat and power - gasification CHP with universal biomass gasifier
Rado Irgl
 
biomass gasification
biomass gasificationbiomass gasification
biomass gasification
Akepati S. Reddy
 
Biomass gassifier
Biomass gassifierBiomass gassifier
Biomass gassifier
Aravind Rajan
 
DIWE - Programming with JavaScript
DIWE - Programming with JavaScriptDIWE - Programming with JavaScript
DIWE - Programming with JavaScript
Rasan Samarasinghe
 
The JavaScript Programming Primer
The JavaScript  Programming PrimerThe JavaScript  Programming Primer
The JavaScript Programming Primer
Mike Wilcox
 
Fabrication and Performance Analysis of Downdraft Biomass Gasifier Using Suga...
Fabrication and Performance Analysis of Downdraft Biomass Gasifier Using Suga...Fabrication and Performance Analysis of Downdraft Biomass Gasifier Using Suga...
Fabrication and Performance Analysis of Downdraft Biomass Gasifier Using Suga...
IJSRD
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
Raghavan Mohan
 
Introduction to web programming with JavaScript
Introduction to web programming with JavaScriptIntroduction to web programming with JavaScript
Introduction to web programming with JavaScript
T11 Sessions
 
Paris Web - Javascript as a programming language
Paris Web - Javascript as a programming languageParis Web - Javascript as a programming language
Paris Web - Javascript as a programming language
Marco Cedaro
 
Reactive Programming with JavaScript
Reactive Programming with JavaScriptReactive Programming with JavaScript
Reactive Programming with JavaScript
Codemotion
 
Javascript Tutorial
Javascript TutorialJavascript Tutorial
Javascript Tutorial
Kang-min Liu
 
Functional Programming in JavaScript
Functional Programming in JavaScriptFunctional Programming in JavaScript
Functional Programming in JavaScript
Troy Miles
 
Biomass gasifier pune
Biomass gasifier  puneBiomass gasifier  pune
Biomass gasifier pune
road2ideas
 
Downdraft biomass gasification: experimental investigation and aspen plus sim...
Downdraft biomass gasification: experimental investigation and aspen plus sim...Downdraft biomass gasification: experimental investigation and aspen plus sim...
Downdraft biomass gasification: experimental investigation and aspen plus sim...
Antonio Geraldo de Paula Oliveira
 
Biomass Gasification presentation
Biomass Gasification presentationBiomass Gasification presentation
Biomass Gasification presentation
Pritish Shardul
 
Biomass heat and power - gasification CHP with universal biomass gasifier
Biomass heat and power - gasification CHP with universal biomass gasifierBiomass heat and power - gasification CHP with universal biomass gasifier
Biomass heat and power - gasification CHP with universal biomass gasifier
Rado Irgl
 
DIWE - Programming with JavaScript
DIWE - Programming with JavaScriptDIWE - Programming with JavaScript
DIWE - Programming with JavaScript
Rasan Samarasinghe
 
Ad

Similar to JavaScript 101 (20)

Python programming workshop session 2
Python programming workshop session 2Python programming workshop session 2
Python programming workshop session 2
Abdul Haseeb
 
C Sharp Jn (3)
C Sharp Jn (3)C Sharp Jn (3)
C Sharp Jn (3)
jahanullah
 
Java căn bản - Chapter6
Java căn bản - Chapter6Java căn bản - Chapter6
Java căn bản - Chapter6
Vince Vo
 
Loops
LoopsLoops
Loops
Kamran
 
introduction to python in english presentation file
introduction to python in english presentation fileintroduction to python in english presentation file
introduction to python in english presentation file
RujanTimsina1
 
Programming ppt files (final)
Programming ppt files (final)Programming ppt files (final)
Programming ppt files (final)
yap_raiza
 
pythonQuick.pdf
pythonQuick.pdfpythonQuick.pdf
pythonQuick.pdf
PhanMinhLinhAnxM0190
 
python notes.pdf
python notes.pdfpython notes.pdf
python notes.pdf
RohitSindhu10
 
python 34💭.pdf
python 34💭.pdfpython 34💭.pdf
python 34💭.pdf
AkashdeepBhattacharj1
 
Python for Beginners(v2)
Python for Beginners(v2)Python for Beginners(v2)
Python for Beginners(v2)
Panimalar Engineering College
 
Ecs 10 programming assignment 4 loopapalooza
Ecs 10 programming assignment 4   loopapaloozaEcs 10 programming assignment 4   loopapalooza
Ecs 10 programming assignment 4 loopapalooza
JenniferBall44
 
Cc code cards
Cc code cardsCc code cards
Cc code cards
ysolanki78
 
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
Anonymous9etQKwW
 
Python programing
Python programingPython programing
Python programing
hamzagame
 
Source code of WPF samples by Microsoft was checked
Source code of WPF samples by Microsoft was checkedSource code of WPF samples by Microsoft was checked
Source code of WPF samples by Microsoft was checked
PVS-Studio
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
GrejoJoby1
 
Vb script tutorial
Vb script tutorialVb script tutorial
Vb script tutorial
Abhishek Kesharwani
 
Chapter1 python introduction syntax general
Chapter1 python introduction syntax generalChapter1 python introduction syntax general
Chapter1 python introduction syntax general
ssuser77162c
 
Web designing unit 4
Web designing unit 4Web designing unit 4
Web designing unit 4
Dr. SURBHI SAROHA
 
Python programming workshop session 2
Python programming workshop session 2Python programming workshop session 2
Python programming workshop session 2
Abdul Haseeb
 
C Sharp Jn (3)
C Sharp Jn (3)C Sharp Jn (3)
C Sharp Jn (3)
jahanullah
 
Java căn bản - Chapter6
Java căn bản - Chapter6Java căn bản - Chapter6
Java căn bản - Chapter6
Vince Vo
 
introduction to python in english presentation file
introduction to python in english presentation fileintroduction to python in english presentation file
introduction to python in english presentation file
RujanTimsina1
 
Programming ppt files (final)
Programming ppt files (final)Programming ppt files (final)
Programming ppt files (final)
yap_raiza
 
Ecs 10 programming assignment 4 loopapalooza
Ecs 10 programming assignment 4   loopapaloozaEcs 10 programming assignment 4   loopapalooza
Ecs 10 programming assignment 4 loopapalooza
JenniferBall44
 
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
Python programing
Python programingPython programing
Python programing
hamzagame
 
Source code of WPF samples by Microsoft was checked
Source code of WPF samples by Microsoft was checkedSource code of WPF samples by Microsoft was checked
Source code of WPF samples by Microsoft was checked
PVS-Studio
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
GrejoJoby1
 
Chapter1 python introduction syntax general
Chapter1 python introduction syntax generalChapter1 python introduction syntax general
Chapter1 python introduction syntax general
ssuser77162c
 
Ad

More from Mindy McAdams (20)

Just Enough Code
Just Enough CodeJust Enough Code
Just Enough Code
Mindy McAdams
 
Multimedia Journalism Innovations in the Classroom
Multimedia Journalism Innovations in the ClassroomMultimedia Journalism Innovations in the Classroom
Multimedia Journalism Innovations in the Classroom
Mindy McAdams
 
Summary of journalism faculty curriculum workshop
Summary of journalism faculty curriculum workshopSummary of journalism faculty curriculum workshop
Summary of journalism faculty curriculum workshop
Mindy McAdams
 
Crowdsourcing
CrowdsourcingCrowdsourcing
Crowdsourcing
Mindy McAdams
 
U.S. j-schools and digital skills
U.S. j-schools and digital skills U.S. j-schools and digital skills
U.S. j-schools and digital skills
Mindy McAdams
 
New skill sets for journalism
New skill sets for journalismNew skill sets for journalism
New skill sets for journalism
Mindy McAdams
 
Journalism blogs: An introduction
Journalism blogs: An introduction Journalism blogs: An introduction
Journalism blogs: An introduction
Mindy McAdams
 
Why Your Newsroom Should Be Using WordPress - ONA13
Why Your Newsroom Should Be Using WordPress - ONA13Why Your Newsroom Should Be Using WordPress - ONA13
Why Your Newsroom Should Be Using WordPress - ONA13
Mindy McAdams
 
Journalism's Future: Journalism, Not Newspapers
Journalism's Future: Journalism, Not NewspapersJournalism's Future: Journalism, Not Newspapers
Journalism's Future: Journalism, Not Newspapers
Mindy McAdams
 
Introduction to HTML5 Canvas
Introduction to HTML5 CanvasIntroduction to HTML5 Canvas
Introduction to HTML5 Canvas
Mindy McAdams
 
An Introduction to the DOM
An Introduction to the DOMAn Introduction to the DOM
An Introduction to the DOM
Mindy McAdams
 
HTML and Responsive Design
HTML and Responsive Design HTML and Responsive Design
HTML and Responsive Design
Mindy McAdams
 
Design Concepts and Web Design
Design Concepts and Web DesignDesign Concepts and Web Design
Design Concepts and Web Design
Mindy McAdams
 
Learning Python - Week 4
Learning Python - Week 4 Learning Python - Week 4
Learning Python - Week 4
Mindy McAdams
 
Learning Python - Week 2
Learning Python - Week 2Learning Python - Week 2
Learning Python - Week 2
Mindy McAdams
 
Learning Python - Week 1
Learning Python - Week 1Learning Python - Week 1
Learning Python - Week 1
Mindy McAdams
 
Learning Python
Learning PythonLearning Python
Learning Python
Mindy McAdams
 
Freedom of Speech - Louis Brandeis
Freedom of Speech - Louis BrandeisFreedom of Speech - Louis Brandeis
Freedom of Speech - Louis Brandeis
Mindy McAdams
 
Networked Information Economy / Benkler
Networked Information Economy / BenklerNetworked Information Economy / Benkler
Networked Information Economy / Benkler
Mindy McAdams
 
Convergence Culture / Jenkins
Convergence Culture / JenkinsConvergence Culture / Jenkins
Convergence Culture / Jenkins
Mindy McAdams
 
Multimedia Journalism Innovations in the Classroom
Multimedia Journalism Innovations in the ClassroomMultimedia Journalism Innovations in the Classroom
Multimedia Journalism Innovations in the Classroom
Mindy McAdams
 
Summary of journalism faculty curriculum workshop
Summary of journalism faculty curriculum workshopSummary of journalism faculty curriculum workshop
Summary of journalism faculty curriculum workshop
Mindy McAdams
 
U.S. j-schools and digital skills
U.S. j-schools and digital skills U.S. j-schools and digital skills
U.S. j-schools and digital skills
Mindy McAdams
 
New skill sets for journalism
New skill sets for journalismNew skill sets for journalism
New skill sets for journalism
Mindy McAdams
 
Journalism blogs: An introduction
Journalism blogs: An introduction Journalism blogs: An introduction
Journalism blogs: An introduction
Mindy McAdams
 
Why Your Newsroom Should Be Using WordPress - ONA13
Why Your Newsroom Should Be Using WordPress - ONA13Why Your Newsroom Should Be Using WordPress - ONA13
Why Your Newsroom Should Be Using WordPress - ONA13
Mindy McAdams
 
Journalism's Future: Journalism, Not Newspapers
Journalism's Future: Journalism, Not NewspapersJournalism's Future: Journalism, Not Newspapers
Journalism's Future: Journalism, Not Newspapers
Mindy McAdams
 
Introduction to HTML5 Canvas
Introduction to HTML5 CanvasIntroduction to HTML5 Canvas
Introduction to HTML5 Canvas
Mindy McAdams
 
An Introduction to the DOM
An Introduction to the DOMAn Introduction to the DOM
An Introduction to the DOM
Mindy McAdams
 
HTML and Responsive Design
HTML and Responsive Design HTML and Responsive Design
HTML and Responsive Design
Mindy McAdams
 
Design Concepts and Web Design
Design Concepts and Web DesignDesign Concepts and Web Design
Design Concepts and Web Design
Mindy McAdams
 
Learning Python - Week 4
Learning Python - Week 4 Learning Python - Week 4
Learning Python - Week 4
Mindy McAdams
 
Learning Python - Week 2
Learning Python - Week 2Learning Python - Week 2
Learning Python - Week 2
Mindy McAdams
 
Learning Python - Week 1
Learning Python - Week 1Learning Python - Week 1
Learning Python - Week 1
Mindy McAdams
 
Freedom of Speech - Louis Brandeis
Freedom of Speech - Louis BrandeisFreedom of Speech - Louis Brandeis
Freedom of Speech - Louis Brandeis
Mindy McAdams
 
Networked Information Economy / Benkler
Networked Information Economy / BenklerNetworked Information Economy / Benkler
Networked Information Economy / Benkler
Mindy McAdams
 
Convergence Culture / Jenkins
Convergence Culture / JenkinsConvergence Culture / Jenkins
Convergence Culture / Jenkins
Mindy McAdams
 

Recently uploaded (20)

YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 

JavaScript 101

  • 1. JavaScript 101 Review from Codecademy exercises Parts 1–12 http://www.codecademy.com/tracks/javascript
  • 2. Comparison JavaScript Python var animal = "elephant" animal.length 8 console.log(animal) elephant 2 + 3 * 5 17 // a comment animal = "elephant" len(animal) 8 print animal elephant 2 + 3 * 5 17 # a comment
  • 3. Comparison JavaScript Python function myfunction(a, b) { var answer = a + b; return answer; } console.log(myfunction(3, 5)); 8 def myfunction(a, b): answer = a + b return answer print (myfunction(3, 5)) 8 var myfunction = function(a, b) { var answer = a + b; return answer; } console.log(myfunction(3, 5)); 8 also JavaScript
  • 4. Alert, Confirm, Prompt An alert dialog box gives a message to the user. It only allows the user to click OK. A confirm dialog box allows the user to choose between OK and Cancel. So the text should ask a question, and clicking OK should cause something to happen. A prompt dialog box allows the user to type something and click OK, or the user may cancel to close the dialog.
  • 5. Alert, Confirm, Prompt We will do an exercise with these later.
  • 6. Booleans: Comparison JavaScript Python 10 > 3 true 10 < 3 false 10 > 3 True 10 < 3 False Note that case is significant in JavaScript (just as it is in Python). The Boolean values in Python must be uppercase. In JavaScript, the Boolean values must be lowercase.
  • 7. If–Else JavaScript Python if (x == y) { console.log("They are equal."); } else if (x > y) { console.log("x is more."); } else { console.log("x is less."); } if (x == y): print "They are equal." elif (x > y): print "x is more." else: print "x is less."
  • 8. For Loop JavaScript Python for ( i = 0; i < 10; i++ ) { console.log(i); } for i in range(0, 10): print i // this will print the numbers from 0 through 9 # this will print the numbers from 0 through 9
  • 10. While Loop JavaScript Python var n = 0; while (n < 3) { console.log("Looping."); n++; } n = 0 while (n < 3): print "Looping." n += 1 Looping. Looping. Looping. Looping. Looping. Looping.
  • 11. “Incrementing” JavaScript i++ is the same as i = i + 1 i-- is the same as i = i - 1 Python i += 1 is the same as i = i + 1 i -= 1 is the same as i = i - 1
  • 12. Extracting a substring JavaScript Python var mystring = "the word swagger" mystring = "the word swagger" console.log(mystring.s ubstring(9,13)); print mystring[9:13] swag swag
  • 13. The switch statement switch (//Some expression) { case 'option1': // Do something break; case 'option2': // Do something else break; default: // Do yet another thing break; }
  • 15. switch (album) { case "asbury": songfile = "clips/spiritinthenight.mp3"; track = "Spirit in the Night"; album = "Greetings from Asbury Park"; break; case "wild": songfile = "clips/fourth.mp3"; track = "4th of July, Asbury Park (Sandy)"; album = "The Wild, the Innocent, and the E Street Shuffle"; break; case "borntorun": songfile = "clips/thunderroad.mp3"; track = "Thunder Road"; album = "Born to Run"; break; . . . . . . . . . . };
  • 16. Arrays (Lists) JavaScript var mylist = ["red", "white", "blue"]; console.log(mylist[2]); blue Python mylist = ["red", "white", "blue"] print mylist[2] blue
  • 17. Math.random() If we declare a variable and make it equal to Math.random(), that variable will equal a number between 0 and 1. Note: In JavaScript, the capital M in all Math methods is significant. No lowercase!
  • 18. Note that if you use Math.random() to create the value of a variable, that value will not change randomly. But if you run Math.random() again and again, it will generate a new number between 0 and 1 each time. To use the JavaScript console in Chrome (shown here), open the View menu > Developer > JavaScript Console
  • 20. What would this code be good for? (Think about games.) Note: Math.floor() rounds a number down to the nearest integer. It conveniently cuts off the decimal places. We add 1 because otherwise our numbers would go from 0 to 5. By adding 1, they range from 1 to 6 instead.
  • 21. Guessing a number • In-class assignment: Create a little game with an HTML page, a confirm dialog box and JavaScript. • Your game will use Math.Random() to pick a number between 1 and … ? (You choose.) • Then the user has to guess the number, by typing it into the confirm dialog. • A new alert box will open and tell the user if the guess is right or wrong.
  • 22. Alert, Confirm, Prompt Download this: https://github.com/maclo o/javascript_beginners
  • 23. JavaScript 101 Review from Codecademy exercises Parts 1–12 http://www.codecademy.com/tracks/javascript

Editor's Notes

  • #2: Presentation by Mindy McAdams, (updated) February 2014. ------ CONTACT ----- http://mindymcadams.com/
  • #3: All programming languages have similarities.
  • #4: Because JavaScript interacts with Web pages and HTML, it does not have the usual PRINT statement. But we can use console.log to “print” when we are testing JavaScript code. Also, JavaScript has two ways to create a new function.
  • #5: One of the common uses of JavaScript on Web pages is to pop up a dialog box. The appearance of these dialog is determined by the browser, so they look different on Mac and Windows. These examples are from the Google Chrome browser on Mac OS.
  • #6: Go to the URL to find code to create these dialog boxes on your own Web pages.
  • #7: All programming languages have similarities.
  • #8: All programming languages have similarities.
  • #9: All programming languages have similarities.
  • #10: All programming languages have similarities.
  • #11: All programming languages have similarities.
  • #13: All programming languages have similarities. The way of counting characters or items (from 0) is identical in JavaScript and Python. Finding a part of a string in this way is part of searching – for example, if you were programming a search engine.
  • #14: NOTE the break – MUST have this. THIS IS IN CODECADEMY PART 9 NOW
  • #15: http://www.jou.ufl.edu/faculty/mmcadams/flash/flashExercise.htmlSEE CODECADEMY PART 9
  • #16: This switch statement (in ActionScript) was used in the Flash graphic shown in the previous slide. Each album cover was a button. When it was clicked, the switch statement changed the value of three different variables depending on which album had been selected. SEE CODECADEMY PART 9
  • #17: All programming languages have similarities.THIS IS IN CODECADEMY PART 11 NOW
  • #18: Codecademy: Math.random() is introduced here -- http://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8
  • #19: To use the JavaScript console in Chrome, open the View menu &gt; Developer &gt; JavaScript Consolehttps://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Math/random
  • #20: Codecademy -- http://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8
  • #21: In the WHILE LOOP section, in Codecademy ------- var coin = Math.floor(Math.random() * 2); To use the JavaScript console in Chrome, open the View menu &gt; Developer &gt; JavaScript ConsoleCode: http://www.the-art-of-web.com/javascript/random/
  • #23: In-class exercise - https://github.com/macloo/javascript_beginners
  • #24: Presentation by Mindy McAdams, (updated) February 2014. ------ CONTACT ----- http://mindymcadams.com/