SlideShare uma empresa Scribd logo
1 de 9
Baixar para ler offline
Intro	
  to	
  Programming	
  for	
  Communicators	
  
                                        Cindy	
  Royal,	
  cindyroyal.com	
  
                                        Hacks/Hackers	
  	
  
                                        Online	
  News	
  Association	
  
	
                                      	
  
Overview	
  
     ¡ JavaScript	
  is	
  a	
  scripting	
  language	
  commonly	
  implemented	
  as	
  part	
  of	
  a	
  web	
  
        browser	
  in	
  order	
  to	
  create	
  enhanced	
  user	
  interfaces	
  and	
  dynamic	
  websites.	
  
     ¡ Can	
  be	
  run	
  client	
  side	
  or	
  server-­‐side	
  (Node.js	
  –	
  a	
  JavaScript	
  environment).	
  
     ¡ Use	
  a	
  text	
  editor	
  to	
  write	
  in	
  an	
  html	
  document,	
  test	
  in	
  browser.	
  
     ¡ Foundation	
  for	
  code	
  libraries	
  like	
  JQuery.	
  
	
  
We’ll	
  be	
  using	
  a	
  text	
  or	
  html	
  editor	
  and	
  a	
  browser	
  for	
  these	
  exercises.	
  
Open	
  a	
  blank	
  document	
  in	
  your	
  text	
  or	
  html	
  editor.	
  Open	
  any	
  browser	
  (preferably	
  IE	
  
9	
  or	
  higher,	
  or	
  Firefox,	
  Chrome.	
  
	
  
Using	
  the	
  Script	
  Tag	
  
The	
  	
  <script>	
  tag	
  is	
  used	
  to	
  present	
  JavaScript	
  in	
  an	
  html	
  document.	
  You	
  don’t	
  have	
  
to	
  add	
  type	
  (for	
  HTML5,	
  type	
  default	
  is	
  “javascript”),	
  but	
  it	
  is	
  not	
  a	
  bad	
  idea	
  to	
  be	
  
specific.	
  Can	
  be	
  placed	
  in	
  head	
  or	
  body	
  of	
  document.	
  
	
  
Ex.	
  	
  
             <script>	
  
             </script>	
  
	
  
or	
  	
  
             <script	
  type=”text/javascript”>	
  
             </script>	
  
	
  
Scripts	
  will	
  go	
  within	
  these	
  tags.	
  
	
  
Write	
  Your	
  First	
  Program	
  
Write	
  the	
  string	
  “Hello	
  World!”	
  to	
  your	
  document	
  
	
  
             <script>	
  	
  
             	
  
             document.write("Hello	
  World!");	
  
             	
  
             </script>	
  
	
  
	
  
	
                                                 	
  
Comments	
  	
  
Developers	
  use	
  comments	
  to	
  leave	
  notes	
  in	
  the	
  code,	
  provide	
  instructions	
  for	
  other	
  
developers	
  or	
  to	
  provide	
  clues	
  to	
  certain	
  techniques.	
  It	
  helps	
  to	
  organize	
  code.	
  
Comments	
  can	
  also	
  be	
  used	
  to	
  temporarily	
  remove	
  and	
  test	
  code	
  without	
  having	
  to	
  
delete	
  it.	
  
	
  
With	
  the	
  script	
  tag.	
  
//	
  This	
  is	
  a	
  comment	
  
/*	
  This	
  is	
  a	
  multi-­‐line	
  
comment	
  */	
  
	
  
Note:	
  basic	
  html	
  comments	
  are	
  handled	
  by	
  <!-­‐-­‐	
  	
  	
  	
  -­‐-­‐>.	
  This	
  would	
  be	
  used	
  in	
  html	
  
documents	
  outside	
  the	
  <script>	
  tag.	
  
	
  
Objects,	
  Properties	
  and	
  Methods	
  
For	
  this	
  exercise,	
  we	
  will	
  mostly	
  be	
  using	
  the	
  document	
  object	
  to	
  write	
  code	
  to	
  the	
  
document	
  loaded	
  in	
  the	
  browser	
  window.	
  We	
  do	
  this	
  by	
  calling	
  the	
  document	
  object	
  
and	
  the	
  write	
  method.	
  	
  
	
  
document.write(“info	
  goes	
  here”);	
  
	
  
Side	
  Note:	
  
The	
  document	
  object	
  is	
  part	
  of	
  the	
  Document	
  Object	
  Model	
  (DOM).	
  There	
  are	
  other	
  
objects	
  associated	
  with	
  the	
  DOM.	
  Some	
  objects	
  are	
  browser	
  objects	
  (i.e.	
  window).	
  
More	
  on	
  this	
  here:	
  http://www.w3schools.com/jsref/default.asp	
  
	
  
Objects	
  can	
  also	
  have	
  properties.	
  Properties	
  don’t	
  have	
  arguments	
  (and	
  therefore	
  
parentheses),	
  but	
  are	
  used	
  to	
  return	
  specific	
  information	
  about	
  the	
  object.	
  
i.e.	
  	
  
document.title;	
  
	
  
This	
  returns	
  the	
  title	
  of	
  the	
  document.	
  You	
  still	
  need	
  a	
  method	
  to	
  tell	
  it	
  what	
  to	
  do	
  
with	
  what	
  it	
  returns.	
  
	
  
document.write(document.title);	
  
	
  
Basic	
  JavaScript	
  Syntax	
  
End	
  lines	
  with	
  semicolon	
  ;	
  
Put	
  arguments	
  in	
  parentheses	
  (	
  )	
  
Period	
  (.)	
  between	
  object	
  and	
  method	
  or	
  property.	
  
Strings	
  in	
  quotation	
  marks	
  “	
  
Anything	
  can	
  be	
  an	
  object	
  in	
  JavaScript	
  –	
  any	
  data	
  type,	
  as	
  you	
  will	
  see	
  as	
  we	
  
progress	
  through	
  the	
  exercises.	
  Some	
  objects	
  are	
  built-­‐in	
  (i.e.	
  document,	
  window),	
  
some	
  can	
  be	
  defined.	
  
	
  
	
                                               	
  
Data	
  Types	
  
String,	
  Number,	
  Boolean,	
  Array,	
  Object,	
  Null,	
  Undefined	
  -­‐	
  programming	
  languages	
  
have	
  syntax	
  and	
  functions	
  that	
  work	
  with	
  a	
  variety	
  of	
  data	
  types.	
  	
  
	
  
We	
  will	
  mainly	
  be	
  concerned	
  with	
  strings	
  and	
  numbers,	
  later	
  adding	
  booleans	
  and	
  
arrays.	
  
	
  
Length	
  
Length	
  is	
  a	
  string	
  property	
  that	
  returns	
  the	
  length	
  of	
  the	
  string.	
  
           <script>	
  
           	
  
           document.write("Hello	
  World!".length);	
  
           	
  
           </script>	
  
	
  
You	
  should	
  see	
  a	
  number	
  that	
  is	
  the	
  length	
  of	
  that	
  string,	
  including	
  the	
  space.	
  
	
  
Concatenation	
  
Use	
  concatenation	
  to	
  join	
  strings.	
  The	
  	
  "	
  	
  	
  "	
  	
  represents	
  a	
  space.	
  
	
  
           <script>	
  	
  
           	
  
           document.write("Hello"	
  +	
  "	
  "	
  +	
  "Cindy!");	
  
           	
  
           </script>	
  
	
  
Variables	
  
Use	
  variables	
  to	
  store	
  numbers	
  and	
  strings	
  
           <script>	
  	
  
           	
  
           var	
  name	
  =	
  "Cindy";	
  
           	
  
           document.write("Hello"	
  +	
  "	
  "	
  +	
  name);	
  
           	
  
           </script>	
  
	
  
and	
  
	
  
           <script>	
  	
  
           var	
  firstname	
  =	
  "Cindy";	
  
           var	
  lastname	
  =	
  "Royal";	
  
           document.write(firstname	
  +	
  "	
  "	
  +	
  lastname);	
  
           </script>	
  
	
  
	
                                          	
  
Math	
  and	
  numbers	
  
Operators	
  and	
  Math	
  	
  
	
  
                Within	
  your	
  script	
  tag,	
  try:	
  
                document.write(3+4);	
  
                document.write(3-­‐4);	
  
                document.write(3*4);	
  
                document.write(3/4);	
  
	
  
	
  
Substrings	
  
I’m	
  using	
  these	
  scripts	
  to	
  see	
  what	
  my	
  JLo	
  name	
  would	
  be,	
  finding	
  the	
  first	
  character	
  
of	
  my	
  first	
  name	
  and	
  the	
  first	
  two	
  characters	
  of	
  my	
  last	
  name.	
  
                <script>	
  	
  
                	
  
                var	
  firstname	
  =	
  "Cindy";	
  
                var	
  lastname	
  =	
  "Royal";	
  
                	
  
                document.write(firstname.substring(0,1)	
  +	
  lastname.substring(0,2));	
  
                	
  
                </script>	
  
	
  or	
  
                <script>	
  	
  
                	
  
                var	
  firstname	
  =	
  "Cindy";	
  
                var	
  lastname	
  =	
  "Royal";	
  
                	
  
                var	
  first	
  =	
  "Cindy".substring(0,1);	
  
                var	
  last	
  =	
  "Royal".substring(0,2);	
  
                document.write(first	
  +	
  last);	
  
                </script>	
  
	
  
Alerts	
  and	
  Prompts	
  
Use	
  these	
  within	
  the	
  <script>	
  tag	
  
	
  
Alert	
  -­‐	
  a	
  general	
  warning	
  
alert("Danger");	
  
	
  
Confirm	
  -­‐	
  answer	
  yes	
  or	
  no	
  
confirm("Are	
  you	
  sure?");	
  
	
  
	
                                              	
  
Prompt	
  -­‐	
  answer	
  anything	
  -­‐	
  creates	
  variable	
  
prompt("What	
  is	
  your	
  name?");	
  
	
  
           <script>	
  	
  
           	
  
           var	
  name	
  =	
  prompt("What	
  is	
  your	
  name?");	
  
           	
  
           document.write("Hello	
  "	
  +	
  name);	
  
           </script>	
  
	
  
Booleans	
  and	
  if	
  statements	
  
Use	
  booleans	
  to	
  test	
  if	
  something	
  is	
  true	
  or	
  false.	
  Combine	
  with	
  an	
  if/else	
  statement	
  
to	
  define	
  different	
  outcomes.	
  Notice	
  that	
  the	
  if	
  statements	
  actions	
  are	
  delineated	
  
with	
  curly	
  braces.	
  	
  
           if(1>2){	
  
           document.write("Yes");	
  
           }	
  
           else	
  {	
  
           document.write("No");	
  
           }	
  
           	
  
Comparisons	
  (=	
  or	
  ==)	
  
A	
  single	
  equal	
  sign	
  (=)	
  indicates	
  assignment,	
  usually	
  used	
  to	
  assign	
  a	
  value	
  to	
  a	
  
variable.	
  If	
  you	
  are	
  doing	
  a	
  mathematical	
  test	
  for	
  comparison,	
  then	
  you	
  use	
  2	
  equal	
  
signs	
  (==).	
  
           2+2==4	
  
           var	
  name=”Cindy”	
  
	
  
Functions	
  
Functions	
  allow	
  you	
  to	
  define	
  an	
  operation	
  and	
  then	
  use	
  it	
  later.	
  Notice	
  the	
  
statements	
  in	
  the	
  function	
  are	
  enclosed	
  in	
  curly	
  braces.	
  	
  
	
  
           <script>	
  	
  
           var	
  hello	
  =	
  function	
  ()	
  {	
  
           var	
  name	
  =	
  prompt("What	
  is	
  your	
  name?");	
  
           document.write("Hello	
  "	
  +	
  name);	
  
           }	
  
           	
  
           hello();	
  
           </script>	
  
	
  
	
                                              	
  
Arguments	
  
You	
  can	
  add	
  arguments	
  in	
  the	
  parentheses	
  of	
  a	
  function	
  to	
  pass	
  information	
  into	
  it.	
  
               <script>	
  	
  
               var	
  hello	
  =	
  function	
  (a)	
  {	
  
               	
  
               document.write("Hello	
  "	
  +	
  a);	
  
               }	
  
               	
  
               hello("Cindy");	
  
               </script>	
  
	
  
Loops	
  	
  
Loops	
  allow	
  for	
  iteration	
  through	
  a	
  cycle.	
  	
  
	
  
The	
  while	
  loop	
  is	
  a	
  statement	
  that	
  uses	
  a	
  variable	
  as	
  initializer,	
  condition	
  and	
  
iterator.	
  	
  
               <script>	
  
               var	
  i=0;	
  	
  
               while	
  (i<5)	
  {	
  
               document.write("I	
  am	
  writing	
  this	
  five	
  times<br	
  />");	
  
               i++;	
  
               }	
  
               	
  
               </script>	
  
	
  
The	
  for	
  loop	
  reduces	
  some	
  of	
  the	
  coding	
  by	
  having	
  three	
  statements	
  in	
  the	
  
parentheses,	
  separated	
  by	
  a	
  semicolon;	
  -­‐	
  an	
  initializer,	
  a	
  condition	
  to	
  test	
  and	
  an	
  
iterator.	
  	
  
               <script>	
  	
  
               for	
  (var	
  i=0;	
  i<4;	
  i++)	
  
               {	
  
               document.write("I	
  am	
  writing	
  this	
  4	
  times<br	
  />");	
  
               }	
  
               </script>	
  
	
  
	
  
Arrays	
  
Arrays	
  allow	
  you	
  to	
  store	
  a	
  collection	
  of	
  information	
  in	
  a	
  variable	
  and	
  then	
  access	
  it	
  
via	
  its	
  index	
  number.	
  Index	
  numbers	
  start	
  with	
  0.	
  
	
  
               <script>	
  
               var	
  favGroups	
  =	
  new	
  Array("Old	
  97s",	
  "Spoon",	
  "Wilco");	
  
               document.write(favGroups[1]);	
  
               </script>	
  
               	
  
	
                                                	
  
You	
  can	
  use	
  a	
  loop	
  to	
  iterate	
  through	
  an	
  array.	
  
	
  
          <script>	
  
          var	
  i=0;	
  
          var	
  favGroups	
  =	
  new	
  Array("Old	
  97s",	
  "Spoon",	
  "Wilco");	
  
          while(i<favGroups.length){	
  
          document.write(favGroups[i]	
  +	
  "<br	
  />");	
  
          i++;	
  
          }	
  
          </script>	
  
          	
  
Using	
  JavaScript	
  in	
  an	
  html	
  document	
  
getElementById();	
  is	
  a	
  magical	
  method	
  that	
  you	
  can	
  use	
  to	
  access	
  parts	
  of	
  a	
  Web	
  
page.	
  
	
  
          <html>	
  
          <head>	
  
          	
  <script>	
  
          	
  
          function	
  nameChange()	
  {	
  
          	
  	
  	
  	
         	
  
          	
                     document.getElementById('first').innerHTML	
  =	
  'Jon';	
  	
  
          }	
  
          	
  
          </script>	
  
          </head>	
  
          <body>	
  
          	
  
                                 <p>Hello	
  <span	
  id="first">Cindy</span></p>	
  
          	
  
          <script>	
  
          	
  	
  	
  	
  	
  nameChange();	
  
          </script>	
  
          	
  
          </body>	
  
          </html>	
  
	
  
	
                                               	
  
Events	
  
An	
  advanced	
  use	
  of	
  JavaScript	
  in	
  an	
  html	
  document	
  has	
  to	
  do	
  with	
  mouse	
  events.	
  An	
  
event	
  is	
  an	
  interaction	
  –	
  onclick,	
  onload,	
  onmouseover,	
  onmouseout.	
  Use	
  events	
  
combined	
  with	
  getElementById()	
  to	
  create	
  interactivity	
  on	
  your	
  site.	
  
	
  
Simple:	
  
              <!DOCTYPE	
  html>	
  
              <html>	
  
              <body>	
  
              <h1	
  onclick="this.innerHTML='Good	
  work!'">Click	
  on	
  this	
  text!</h1>	
  
              </body>	
  
              </html>	
  
	
  
In	
  a	
  function:	
  
              <!DOCTYPE	
  html>	
  
              <html>	
  
              <head>	
  
              <script>	
  
              function	
  changetext(id)	
  
              {	
  
              id.innerHTML="You’re	
  a	
  pro!";	
  
              }	
  
              </script>	
  
              </head>	
  
              <body>	
  
              <h1	
  onclick="changetext(this)">Click	
  on	
  this	
  text!</h1>	
  
              </body>	
  
              </html>	
  
	
  
	
                                          	
  
More	
  advanced	
  use	
  of	
  getElementById()	
  with	
  form	
  
This	
  form	
  asks	
  you	
  to	
  select	
  your	
  favorite	
  browser,	
  then	
  it	
  stores	
  that	
  info	
  in	
  a	
  
variable	
  and	
  presents	
  it	
  in	
  an	
  a	
  box	
  on	
  the	
  page.	
  
            	
  
            <!DOCTYPE	
  html>	
  
            <html>	
  
            <head>	
  
            <script>	
  
            function	
  favBrowser()	
  
            {	
  
            var	
  mylist=document.getElementById("myList");	
  
            document.getElementById("favorite").value=mylist.options[mylist.selectedIn
            dex].text;	
  
            }	
  
            </script>	
  
            </head>	
  
            	
  
            <body>	
  
            <form>	
  
            Select	
  your	
  favorite	
  browser:	
  
            <select	
  id="myList"	
  onchange="favBrowser()">	
  
            	
  	
  <option></option>	
  
            	
  	
  <option>Google	
  Chrome</option>	
  
            	
  	
  <option>Firefox</option>	
  	
  	
  
            	
  	
  <option>Internet	
  Explorer</option>	
  
            	
  	
  <option>Safari</option>	
  
            	
  	
  <option>Opera</option>	
  
            </select>	
  
            <p>Your	
  favorite	
  browser	
  is:	
  <input	
  type="text"	
  id="favorite"	
  
            size="20"></p>	
  
            </form>	
  
            </body>	
  
            </html>	
  
            	
  
Now	
  you	
  have	
  a	
  basic	
  understanding	
  of	
  programming	
  concepts.	
  There	
  are	
  many	
  
ways	
  to	
  go	
  from	
  here.	
  You	
  can	
  learn	
  more	
  about	
  coding	
  Web	
  pages	
  with	
  HTML/CSS,	
  
so	
  that	
  you	
  can	
  integrate	
  interactive	
  concepts.	
  Or	
  you	
  can	
  move	
  into	
  the	
  world	
  of	
  
JQuery	
  to	
  learn	
  how	
  to	
  take	
  advantage	
  of	
  coding	
  libraries.	
  	
  
	
  
You	
  can	
  study	
  other	
  programming	
  languages	
  and	
  learn	
  their	
  unique	
  approaches	
  to	
  
syntax	
  and	
  basic	
  concepts.	
  
	
  
And	
  you	
  can	
  look	
  for	
  code	
  samples	
  online	
  and	
  make	
  modifications	
  to	
  them	
  to	
  
customize	
  for	
  your	
  own	
  purposes.	
  	
  Much	
  coding	
  is	
  done	
  by	
  	
  modifying	
  items	
  that	
  
already	
  exist,	
  so	
  you	
  are	
  now	
  equipped	
  to	
  tweak	
  away!	
  
	
  

Mais conteúdo relacionado

Mais procurados

JavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQuery
Jamshid Hashimi
 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentation
Adhoura Academy
 
Php object orientation and classes
Php object orientation and classesPhp object orientation and classes
Php object orientation and classes
Kumar
 

Mais procurados (20)

Introduction to JavaScript Basics.
Introduction to JavaScript Basics.Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
 
Java script basics
Java script basicsJava script basics
Java script basics
 
Java script -23jan2015
Java script -23jan2015Java script -23jan2015
Java script -23jan2015
 
JavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQuery
 
Lab#1 - Front End Development
Lab#1 - Front End DevelopmentLab#1 - Front End Development
Lab#1 - Front End Development
 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentation
 
Javascript functions
Javascript functionsJavascript functions
Javascript functions
 
Javascript
JavascriptJavascript
Javascript
 
Jscript part2
Jscript part2Jscript part2
Jscript part2
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
 
Java script
Java scriptJava script
Java script
 
Complete Notes on Angular 2 and TypeScript
Complete Notes on Angular 2 and TypeScriptComplete Notes on Angular 2 and TypeScript
Complete Notes on Angular 2 and TypeScript
 
Php object orientation and classes
Php object orientation and classesPhp object orientation and classes
Php object orientation and classes
 
Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java script
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
Java script
Java scriptJava script
Java script
 
Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy steps
 
Placement and variable 03 (js)
Placement and variable 03 (js)Placement and variable 03 (js)
Placement and variable 03 (js)
 
Html JavaScript and CSS
Html JavaScript and CSSHtml JavaScript and CSS
Html JavaScript and CSS
 

Destaque

Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Towards Improving Interface Modularity in Legacy Java Software Through Automa...Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
New York City College of Technology Computer Systems Technology Colloquium
 

Destaque (20)

Sant Cugat
Sant CugatSant Cugat
Sant Cugat
 
6 471 acil kombi çağrı merkezi
6 471 acil kombi çağrı merkezi6 471 acil kombi çağrı merkezi
6 471 acil kombi çağrı merkezi
 
Mapa conceptual
Mapa conceptualMapa conceptual
Mapa conceptual
 
Untitled Presentation
Untitled PresentationUntitled Presentation
Untitled Presentation
 
presentacion
presentacionpresentacion
presentacion
 
Sunshine Coast Futures Conference 2015
Sunshine Coast Futures Conference 2015Sunshine Coast Futures Conference 2015
Sunshine Coast Futures Conference 2015
 
El proceso tecnologico
El proceso tecnologicoEl proceso tecnologico
El proceso tecnologico
 
ほっとらいん相談の手引
ほっとらいん相談の手引ほっとらいん相談の手引
ほっとらいん相談の手引
 
dave
davedave
dave
 
Cultivating Mid-Level Donors
Cultivating Mid-Level DonorsCultivating Mid-Level Donors
Cultivating Mid-Level Donors
 
Toward a More Innovative Curriculum
Toward a More Innovative CurriculumToward a More Innovative Curriculum
Toward a More Innovative Curriculum
 
Quynh
QuynhQuynh
Quynh
 
Unraveling urban traffic flows
Unraveling urban traffic flowsUnraveling urban traffic flows
Unraveling urban traffic flows
 
Basvuru formu1
Basvuru formu1Basvuru formu1
Basvuru formu1
 
NICK IT'S YOUR BIRTHDAY AHHHH
NICK IT'S YOUR BIRTHDAY AHHHHNICK IT'S YOUR BIRTHDAY AHHHH
NICK IT'S YOUR BIRTHDAY AHHHH
 
When new meets old - online research methods for governement
When new meets old - online research methods for governementWhen new meets old - online research methods for governement
When new meets old - online research methods for governement
 
The Future Of Giving: Why Students And Young Alumni Matter
The Future Of Giving: Why Students And Young Alumni MatterThe Future Of Giving: Why Students And Young Alumni Matter
The Future Of Giving: Why Students And Young Alumni Matter
 
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Towards Improving Interface Modularity in Legacy Java Software Through Automa...Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
 
4150415
41504154150415
4150415
 
정품드래곤발기제♤w5.ow.to ☆톡 w2015♤ 드래곤발기제 종류, 드래곤발기제 구매,드래곤발기제 약효, 드래곤발기제 정품구입
정품드래곤발기제♤w5.ow.to ☆톡 w2015♤ 드래곤발기제 종류, 드래곤발기제 구매,드래곤발기제 약효, 드래곤발기제 정품구입정품드래곤발기제♤w5.ow.to ☆톡 w2015♤ 드래곤발기제 종류, 드래곤발기제 구매,드래곤발기제 약효, 드래곤발기제 정품구입
정품드래곤발기제♤w5.ow.to ☆톡 w2015♤ 드래곤발기제 종류, 드래곤발기제 구매,드래곤발기제 약효, 드래곤발기제 정품구입
 

Semelhante a Intro to Programming for Communicators - Hacks/Hackers ATX

Javascript part1
Javascript part1Javascript part1
Javascript part1
Raghu nath
 
10. session 10 loops and arrays
10. session 10   loops and arrays10. session 10   loops and arrays
10. session 10 loops and arrays
Phúc Đỗ
 

Semelhante a Intro to Programming for Communicators - Hacks/Hackers ATX (20)

Handout - Introduction to Programming
Handout - Introduction to ProgrammingHandout - Introduction to Programming
Handout - Introduction to Programming
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java script
 
FYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III JavascriptFYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III Javascript
 
Reversing JavaScript
Reversing JavaScriptReversing JavaScript
Reversing JavaScript
 
1. java script language fundamentals
1. java script language fundamentals1. java script language fundamentals
1. java script language fundamentals
 
2javascript web programming with JAVA script
2javascript web programming with JAVA script2javascript web programming with JAVA script
2javascript web programming with JAVA script
 
"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues
 
JavaScript_III.pptx
JavaScript_III.pptxJavaScript_III.pptx
JavaScript_III.pptx
 
Javascript1
Javascript1Javascript1
Javascript1
 
Javascript part1
Javascript part1Javascript part1
Javascript part1
 
Javascript
JavascriptJavascript
Javascript
 
Javascript
JavascriptJavascript
Javascript
 
Lecture17 ie321 dr_atifshahzad_js
Lecture17 ie321 dr_atifshahzad_jsLecture17 ie321 dr_atifshahzad_js
Lecture17 ie321 dr_atifshahzad_js
 
IT2255 Web Essentials - Unit III Client-Side Processing and Scripting
IT2255 Web Essentials - Unit III Client-Side Processing and ScriptingIT2255 Web Essentials - Unit III Client-Side Processing and Scripting
IT2255 Web Essentials - Unit III Client-Side Processing and Scripting
 
Java script
Java scriptJava script
Java script
 
10. session 10 loops and arrays
10. session 10   loops and arrays10. session 10   loops and arrays
10. session 10 loops and arrays
 
php&mysql with Ethical Hacking
php&mysql with Ethical Hackingphp&mysql with Ethical Hacking
php&mysql with Ethical Hacking
 
iOS best practices
iOS best practicesiOS best practices
iOS best practices
 
Angular JS2 Training Session #1
Angular JS2 Training Session #1Angular JS2 Training Session #1
Angular JS2 Training Session #1
 

Mais de Cindy Royal

Final Review - FDOM
Final Review - FDOMFinal Review - FDOM
Final Review - FDOM
Cindy Royal
 
ONA: 7 Things Everyone Should Know
ONA: 7 Things Everyone Should KnowONA: 7 Things Everyone Should Know
ONA: 7 Things Everyone Should Know
Cindy Royal
 
Trends in Online Media - ASNE 2011
Trends in Online Media - ASNE 2011Trends in Online Media - ASNE 2011
Trends in Online Media - ASNE 2011
Cindy Royal
 

Mais de Cindy Royal (20)

Why Should Communicators Learn to Code?
Why Should Communicators Learn to Code?Why Should Communicators Learn to Code?
Why Should Communicators Learn to Code?
 
Agile Development
Agile DevelopmentAgile Development
Agile Development
 
Design Thinking for Bienestar Coalition
Design Thinking for Bienestar CoalitionDesign Thinking for Bienestar Coalition
Design Thinking for Bienestar Coalition
 
Bienestar - Collaboration Tools
Bienestar - Collaboration ToolsBienestar - Collaboration Tools
Bienestar - Collaboration Tools
 
Bienestar - Social Media Workshop
Bienestar - Social Media WorkshopBienestar - Social Media Workshop
Bienestar - Social Media Workshop
 
Cali
CaliCali
Cali
 
Final Review - FDOM
Final Review - FDOMFinal Review - FDOM
Final Review - FDOM
 
SXTXState Final Presentation
SXTXState Final PresentationSXTXState Final Presentation
SXTXState Final Presentation
 
Women in IT Panel Intro
Women in IT Panel IntroWomen in IT Panel Intro
Women in IT Panel Intro
 
Intro to Programming for Communicators - Intro Slides
Intro to Programming for Communicators - Intro SlidesIntro to Programming for Communicators - Intro Slides
Intro to Programming for Communicators - Intro Slides
 
Researching Digital Media
Researching Digital MediaResearching Digital Media
Researching Digital Media
 
Social Media: Taking It to the Next Level - Business application
Social Media: Taking It to the Next Level - Business applicationSocial Media: Taking It to the Next Level - Business application
Social Media: Taking It to the Next Level - Business application
 
Social Media Techniques - 2012
Social Media Techniques - 2012Social Media Techniques - 2012
Social Media Techniques - 2012
 
Social Media: Taking It to the Next Level
Social Media: Taking It to the Next LevelSocial Media: Taking It to the Next Level
Social Media: Taking It to the Next Level
 
Storify It!
Storify It!Storify It!
Storify It!
 
ONA: 7 Things Everyone Should Know
ONA: 7 Things Everyone Should KnowONA: 7 Things Everyone Should Know
ONA: 7 Things Everyone Should Know
 
News as User Experience
News as User ExperienceNews as User Experience
News as User Experience
 
Social Media in the Classroom - Political
Social Media in the Classroom - PoliticalSocial Media in the Classroom - Political
Social Media in the Classroom - Political
 
Social Media for Magazines - AEJMC 2011
Social Media for Magazines - AEJMC 2011Social Media for Magazines - AEJMC 2011
Social Media for Magazines - AEJMC 2011
 
Trends in Online Media - ASNE 2011
Trends in Online Media - ASNE 2011Trends in Online Media - ASNE 2011
Trends in Online Media - ASNE 2011
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
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...
 
[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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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...
 
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
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

Intro to Programming for Communicators - Hacks/Hackers ATX

  • 1. Intro  to  Programming  for  Communicators   Cindy  Royal,  cindyroyal.com   Hacks/Hackers     Online  News  Association       Overview   ¡ JavaScript  is  a  scripting  language  commonly  implemented  as  part  of  a  web   browser  in  order  to  create  enhanced  user  interfaces  and  dynamic  websites.   ¡ Can  be  run  client  side  or  server-­‐side  (Node.js  –  a  JavaScript  environment).   ¡ Use  a  text  editor  to  write  in  an  html  document,  test  in  browser.   ¡ Foundation  for  code  libraries  like  JQuery.     We’ll  be  using  a  text  or  html  editor  and  a  browser  for  these  exercises.   Open  a  blank  document  in  your  text  or  html  editor.  Open  any  browser  (preferably  IE   9  or  higher,  or  Firefox,  Chrome.     Using  the  Script  Tag   The    <script>  tag  is  used  to  present  JavaScript  in  an  html  document.  You  don’t  have   to  add  type  (for  HTML5,  type  default  is  “javascript”),  but  it  is  not  a  bad  idea  to  be   specific.  Can  be  placed  in  head  or  body  of  document.     Ex.     <script>   </script>     or     <script  type=”text/javascript”>   </script>     Scripts  will  go  within  these  tags.     Write  Your  First  Program   Write  the  string  “Hello  World!”  to  your  document     <script>       document.write("Hello  World!");     </script>          
  • 2. Comments     Developers  use  comments  to  leave  notes  in  the  code,  provide  instructions  for  other   developers  or  to  provide  clues  to  certain  techniques.  It  helps  to  organize  code.   Comments  can  also  be  used  to  temporarily  remove  and  test  code  without  having  to   delete  it.     With  the  script  tag.   //  This  is  a  comment   /*  This  is  a  multi-­‐line   comment  */     Note:  basic  html  comments  are  handled  by  <!-­‐-­‐        -­‐-­‐>.  This  would  be  used  in  html   documents  outside  the  <script>  tag.     Objects,  Properties  and  Methods   For  this  exercise,  we  will  mostly  be  using  the  document  object  to  write  code  to  the   document  loaded  in  the  browser  window.  We  do  this  by  calling  the  document  object   and  the  write  method.       document.write(“info  goes  here”);     Side  Note:   The  document  object  is  part  of  the  Document  Object  Model  (DOM).  There  are  other   objects  associated  with  the  DOM.  Some  objects  are  browser  objects  (i.e.  window).   More  on  this  here:  http://www.w3schools.com/jsref/default.asp     Objects  can  also  have  properties.  Properties  don’t  have  arguments  (and  therefore   parentheses),  but  are  used  to  return  specific  information  about  the  object.   i.e.     document.title;     This  returns  the  title  of  the  document.  You  still  need  a  method  to  tell  it  what  to  do   with  what  it  returns.     document.write(document.title);     Basic  JavaScript  Syntax   End  lines  with  semicolon  ;   Put  arguments  in  parentheses  (  )   Period  (.)  between  object  and  method  or  property.   Strings  in  quotation  marks  “   Anything  can  be  an  object  in  JavaScript  –  any  data  type,  as  you  will  see  as  we   progress  through  the  exercises.  Some  objects  are  built-­‐in  (i.e.  document,  window),   some  can  be  defined.        
  • 3. Data  Types   String,  Number,  Boolean,  Array,  Object,  Null,  Undefined  -­‐  programming  languages   have  syntax  and  functions  that  work  with  a  variety  of  data  types.       We  will  mainly  be  concerned  with  strings  and  numbers,  later  adding  booleans  and   arrays.     Length   Length  is  a  string  property  that  returns  the  length  of  the  string.   <script>     document.write("Hello  World!".length);     </script>     You  should  see  a  number  that  is  the  length  of  that  string,  including  the  space.     Concatenation   Use  concatenation  to  join  strings.  The    "      "    represents  a  space.     <script>       document.write("Hello"  +  "  "  +  "Cindy!");     </script>     Variables   Use  variables  to  store  numbers  and  strings   <script>       var  name  =  "Cindy";     document.write("Hello"  +  "  "  +  name);     </script>     and     <script>     var  firstname  =  "Cindy";   var  lastname  =  "Royal";   document.write(firstname  +  "  "  +  lastname);   </script>        
  • 4. Math  and  numbers   Operators  and  Math       Within  your  script  tag,  try:   document.write(3+4);   document.write(3-­‐4);   document.write(3*4);   document.write(3/4);       Substrings   I’m  using  these  scripts  to  see  what  my  JLo  name  would  be,  finding  the  first  character   of  my  first  name  and  the  first  two  characters  of  my  last  name.   <script>       var  firstname  =  "Cindy";   var  lastname  =  "Royal";     document.write(firstname.substring(0,1)  +  lastname.substring(0,2));     </script>    or   <script>       var  firstname  =  "Cindy";   var  lastname  =  "Royal";     var  first  =  "Cindy".substring(0,1);   var  last  =  "Royal".substring(0,2);   document.write(first  +  last);   </script>     Alerts  and  Prompts   Use  these  within  the  <script>  tag     Alert  -­‐  a  general  warning   alert("Danger");     Confirm  -­‐  answer  yes  or  no   confirm("Are  you  sure?");        
  • 5. Prompt  -­‐  answer  anything  -­‐  creates  variable   prompt("What  is  your  name?");     <script>       var  name  =  prompt("What  is  your  name?");     document.write("Hello  "  +  name);   </script>     Booleans  and  if  statements   Use  booleans  to  test  if  something  is  true  or  false.  Combine  with  an  if/else  statement   to  define  different  outcomes.  Notice  that  the  if  statements  actions  are  delineated   with  curly  braces.     if(1>2){   document.write("Yes");   }   else  {   document.write("No");   }     Comparisons  (=  or  ==)   A  single  equal  sign  (=)  indicates  assignment,  usually  used  to  assign  a  value  to  a   variable.  If  you  are  doing  a  mathematical  test  for  comparison,  then  you  use  2  equal   signs  (==).   2+2==4   var  name=”Cindy”     Functions   Functions  allow  you  to  define  an  operation  and  then  use  it  later.  Notice  the   statements  in  the  function  are  enclosed  in  curly  braces.       <script>     var  hello  =  function  ()  {   var  name  =  prompt("What  is  your  name?");   document.write("Hello  "  +  name);   }     hello();   </script>        
  • 6. Arguments   You  can  add  arguments  in  the  parentheses  of  a  function  to  pass  information  into  it.   <script>     var  hello  =  function  (a)  {     document.write("Hello  "  +  a);   }     hello("Cindy");   </script>     Loops     Loops  allow  for  iteration  through  a  cycle.       The  while  loop  is  a  statement  that  uses  a  variable  as  initializer,  condition  and   iterator.     <script>   var  i=0;     while  (i<5)  {   document.write("I  am  writing  this  five  times<br  />");   i++;   }     </script>     The  for  loop  reduces  some  of  the  coding  by  having  three  statements  in  the   parentheses,  separated  by  a  semicolon;  -­‐  an  initializer,  a  condition  to  test  and  an   iterator.     <script>     for  (var  i=0;  i<4;  i++)   {   document.write("I  am  writing  this  4  times<br  />");   }   </script>       Arrays   Arrays  allow  you  to  store  a  collection  of  information  in  a  variable  and  then  access  it   via  its  index  number.  Index  numbers  start  with  0.     <script>   var  favGroups  =  new  Array("Old  97s",  "Spoon",  "Wilco");   document.write(favGroups[1]);   </script>        
  • 7. You  can  use  a  loop  to  iterate  through  an  array.     <script>   var  i=0;   var  favGroups  =  new  Array("Old  97s",  "Spoon",  "Wilco");   while(i<favGroups.length){   document.write(favGroups[i]  +  "<br  />");   i++;   }   </script>     Using  JavaScript  in  an  html  document   getElementById();  is  a  magical  method  that  you  can  use  to  access  parts  of  a  Web   page.     <html>   <head>    <script>     function  nameChange()  {               document.getElementById('first').innerHTML  =  'Jon';     }     </script>   </head>   <body>     <p>Hello  <span  id="first">Cindy</span></p>     <script>            nameChange();   </script>     </body>   </html>        
  • 8. Events   An  advanced  use  of  JavaScript  in  an  html  document  has  to  do  with  mouse  events.  An   event  is  an  interaction  –  onclick,  onload,  onmouseover,  onmouseout.  Use  events   combined  with  getElementById()  to  create  interactivity  on  your  site.     Simple:   <!DOCTYPE  html>   <html>   <body>   <h1  onclick="this.innerHTML='Good  work!'">Click  on  this  text!</h1>   </body>   </html>     In  a  function:   <!DOCTYPE  html>   <html>   <head>   <script>   function  changetext(id)   {   id.innerHTML="You’re  a  pro!";   }   </script>   </head>   <body>   <h1  onclick="changetext(this)">Click  on  this  text!</h1>   </body>   </html>        
  • 9. More  advanced  use  of  getElementById()  with  form   This  form  asks  you  to  select  your  favorite  browser,  then  it  stores  that  info  in  a   variable  and  presents  it  in  an  a  box  on  the  page.     <!DOCTYPE  html>   <html>   <head>   <script>   function  favBrowser()   {   var  mylist=document.getElementById("myList");   document.getElementById("favorite").value=mylist.options[mylist.selectedIn dex].text;   }   </script>   </head>     <body>   <form>   Select  your  favorite  browser:   <select  id="myList"  onchange="favBrowser()">      <option></option>      <option>Google  Chrome</option>      <option>Firefox</option>          <option>Internet  Explorer</option>      <option>Safari</option>      <option>Opera</option>   </select>   <p>Your  favorite  browser  is:  <input  type="text"  id="favorite"   size="20"></p>   </form>   </body>   </html>     Now  you  have  a  basic  understanding  of  programming  concepts.  There  are  many   ways  to  go  from  here.  You  can  learn  more  about  coding  Web  pages  with  HTML/CSS,   so  that  you  can  integrate  interactive  concepts.  Or  you  can  move  into  the  world  of   JQuery  to  learn  how  to  take  advantage  of  coding  libraries.       You  can  study  other  programming  languages  and  learn  their  unique  approaches  to   syntax  and  basic  concepts.     And  you  can  look  for  code  samples  online  and  make  modifications  to  them  to   customize  for  your  own  purposes.    Much  coding  is  done  by    modifying  items  that   already  exist,  so  you  are  now  equipped  to  tweak  away!