SlideShare ist ein Scribd-Unternehmen logo
1 von 9
Downloaden Sie, um offline zu lesen
Intro	
  to	
  Programming	
  for	
  Communicators	
  
                                        Cindy	
  Royal,	
  cindyroyal.com	
  
                                        Hacks/Hackers	
  	
  
                                        Online	
  News	
  Association	
  
	
                                      slideshare.net/cindyroyal	
  
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.	
  
	
  
Save	
  your	
  files	
  with	
  a	
  .html	
  extension	
  (any	
  name	
  is	
  fine,	
  something	
  like	
  
javascript.html).	
  We	
  won’t	
  be	
  covering	
  HTML,	
  but	
  we	
  will	
  be	
  opening	
  the	
  html	
  file	
  
that	
  includes	
  the	
  JavaScript	
  in	
  the	
  browser.	
  	
  
	
  
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	
  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.selectedIndex].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!	
  
	
  

Weitere ähnliche Inhalte

Was ist angesagt?

php&mysql with Ethical Hacking
php&mysql with Ethical Hackingphp&mysql with Ethical Hacking
php&mysql with Ethical HackingBCET
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingHoat Le
 
clean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionclean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionsaber tabatabaee
 
Doctrator Symfony Live 2011 San Francisco
Doctrator Symfony Live 2011 San FranciscoDoctrator Symfony Live 2011 San Francisco
Doctrator Symfony Live 2011 San Franciscopablodip
 
Introduction to OOP with PHP
Introduction to OOP with PHPIntroduction to OOP with PHP
Introduction to OOP with PHPMichael Peacock
 
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009Heiko Behrens
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScriptAndres Baravalle
 
Object oreinted php | OOPs
Object oreinted php | OOPsObject oreinted php | OOPs
Object oreinted php | OOPsRavi Bhadauria
 
Rails workshop for Java people (September 2015)
Rails workshop for Java people (September 2015)Rails workshop for Java people (September 2015)
Rails workshop for Java people (September 2015)Andre Foeken
 
Nedap Rails Workshop
Nedap Rails WorkshopNedap Rails Workshop
Nedap Rails WorkshopAndre Foeken
 
Programming Languages and their influence in Thinking
Programming Languages and their influence in ThinkingProgramming Languages and their influence in Thinking
Programming Languages and their influence in ThinkingHernan Wilkinson
 
JavaScript introduction 1 ( Variables And Values )
JavaScript introduction 1 ( Variables And Values )JavaScript introduction 1 ( Variables And Values )
JavaScript introduction 1 ( Variables And Values )Victor Verhaagen
 

Was ist angesagt? (20)

php&mysql with Ethical Hacking
php&mysql with Ethical Hackingphp&mysql with Ethical Hacking
php&mysql with Ethical Hacking
 
Java script
Java scriptJava script
Java script
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
 
Writing clean code
Writing clean codeWriting clean code
Writing clean code
 
OO in JavaScript
OO in JavaScriptOO in JavaScript
OO in JavaScript
 
clean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionclean code book summary - uncle bob - English version
clean code book summary - uncle bob - English version
 
Doctrator Symfony Live 2011 San Francisco
Doctrator Symfony Live 2011 San FranciscoDoctrator Symfony Live 2011 San Francisco
Doctrator Symfony Live 2011 San Francisco
 
Php Oop
Php OopPhp Oop
Php Oop
 
Introduction to OOP with PHP
Introduction to OOP with PHPIntroduction to OOP with PHP
Introduction to OOP with PHP
 
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
 
PHP Classes and OOPS Concept
PHP Classes and OOPS ConceptPHP Classes and OOPS Concept
PHP Classes and OOPS Concept
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Lecture7
Lecture7Lecture7
Lecture7
 
Object oreinted php | OOPs
Object oreinted php | OOPsObject oreinted php | OOPs
Object oreinted php | OOPs
 
Rails workshop for Java people (September 2015)
Rails workshop for Java people (September 2015)Rails workshop for Java people (September 2015)
Rails workshop for Java people (September 2015)
 
Nedap Rails Workshop
Nedap Rails WorkshopNedap Rails Workshop
Nedap Rails Workshop
 
Os Borger
Os BorgerOs Borger
Os Borger
 
The Xtext Grammar Language
The Xtext Grammar LanguageThe Xtext Grammar Language
The Xtext Grammar Language
 
Programming Languages and their influence in Thinking
Programming Languages and their influence in ThinkingProgramming Languages and their influence in Thinking
Programming Languages and their influence in Thinking
 
JavaScript introduction 1 ( Variables And Values )
JavaScript introduction 1 ( Variables And Values )JavaScript introduction 1 ( Variables And Values )
JavaScript introduction 1 ( Variables And Values )
 

Ähnlich wie Intro to Programming for Communicators - Hacks/Hackers ATX

Handout - Introduction to Programming
Handout - Introduction to ProgrammingHandout - Introduction to Programming
Handout - Introduction to ProgrammingCindy Royal
 
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 JavascriptArti Parab Academics
 
Lecture17 ie321 dr_atifshahzad_js
Lecture17 ie321 dr_atifshahzad_jsLecture17 ie321 dr_atifshahzad_js
Lecture17 ie321 dr_atifshahzad_jsAtif Shahzad
 
1. java script language fundamentals
1. java script language fundamentals1. java script language fundamentals
1. java script language fundamentalsRajiv Gupta
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java scriptnanjil1984
 
Javascript part1
Javascript part1Javascript part1
Javascript part1Raghu nath
 
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
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side JavascriptJulie Iskander
 
Java script
 Java script Java script
Java scriptbosybosy
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypesVarun C M
 
10. session 10 loops and arrays
10. session 10   loops and arrays10. session 10   loops and arrays
10. session 10 loops and arraysPhúc Đỗ
 
Angular JS2 Training Session #1
Angular JS2 Training Session #1Angular JS2 Training Session #1
Angular JS2 Training Session #1Paras Mendiratta
 
2javascript web programming with JAVA script
2javascript web programming with JAVA script2javascript web programming with JAVA script
2javascript web programming with JAVA scriptumardanjumamaiwada
 
Javascript sivasoft
Javascript sivasoftJavascript sivasoft
Javascript sivasoftch samaram
 

Ähnlich wie 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
 
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
 
Javascript1
Javascript1Javascript1
Javascript1
 
Lecture17 ie321 dr_atifshahzad_js
Lecture17 ie321 dr_atifshahzad_jsLecture17 ie321 dr_atifshahzad_js
Lecture17 ie321 dr_atifshahzad_js
 
1. java script language fundamentals
1. java script language fundamentals1. java script language fundamentals
1. java script language fundamentals
 
Reversing JavaScript
Reversing JavaScriptReversing JavaScript
Reversing JavaScript
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java script
 
Javascript part1
Javascript part1Javascript part1
Javascript part1
 
"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues
 
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
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
 
Java script
 Java script Java script
Java script
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
10. session 10 loops and arrays
10. session 10   loops and arrays10. session 10   loops and arrays
10. session 10 loops and arrays
 
Javascript
JavascriptJavascript
Javascript
 
Angular JS2 Training Session #1
Angular JS2 Training Session #1Angular JS2 Training Session #1
Angular JS2 Training Session #1
 
Javascript
JavascriptJavascript
Javascript
 
2javascript web programming with JAVA script
2javascript web programming with JAVA script2javascript web programming with JAVA script
2javascript web programming with JAVA script
 
Javascript sivasoft
Javascript sivasoftJavascript sivasoft
Javascript sivasoft
 

Mehr von Cindy Royal

PhDigital 2020: Web Development
PhDigital 2020: Web DevelopmentPhDigital 2020: Web Development
PhDigital 2020: Web DevelopmentCindy Royal
 
Redefining Doctoral Education: Preparing Future Faculty to Lead Emerging Med...
Redefining Doctoral Education:  Preparing Future Faculty to Lead Emerging Med...Redefining Doctoral Education:  Preparing Future Faculty to Lead Emerging Med...
Redefining Doctoral Education: Preparing Future Faculty to Lead Emerging Med...Cindy Royal
 
Product Management
Product ManagementProduct Management
Product ManagementCindy Royal
 
Digital Product Management
Digital Product ManagementDigital Product Management
Digital Product ManagementCindy Royal
 
Bending, Breaking and Blending the Academy
Bending, Breaking and Blending the AcademyBending, Breaking and Blending the Academy
Bending, Breaking and Blending the AcademyCindy Royal
 
Taking Control of Social Media For Your Career
Taking Control of Social Media For Your CareerTaking Control of Social Media For Your Career
Taking Control of Social Media For Your CareerCindy Royal
 
Bootstrap Web Development Framework
Bootstrap Web Development FrameworkBootstrap Web Development Framework
Bootstrap Web Development FrameworkCindy Royal
 
Web Development Intro
Web Development IntroWeb Development Intro
Web Development IntroCindy Royal
 
PhDigital Bootcamp: Web Development Concepts
PhDigital Bootcamp: Web Development ConceptsPhDigital Bootcamp: Web Development Concepts
PhDigital Bootcamp: Web Development ConceptsCindy Royal
 
PhDigital Bootcamp: Digital Product Management
PhDigital Bootcamp: Digital Product ManagementPhDigital Bootcamp: Digital Product Management
PhDigital Bootcamp: Digital Product ManagementCindy Royal
 
Digital and Social Certifications
Digital and Social CertificationsDigital and Social Certifications
Digital and Social CertificationsCindy Royal
 
MiLab Presentation 2018
MiLab Presentation 2018MiLab Presentation 2018
MiLab Presentation 2018Cindy Royal
 
Is Your Curriculum Digital Enough?
Is Your Curriculum Digital Enough?Is Your Curriculum Digital Enough?
Is Your Curriculum Digital Enough?Cindy Royal
 
Fundamentals of Digital/Online Media
Fundamentals of Digital/Online MediaFundamentals of Digital/Online Media
Fundamentals of Digital/Online MediaCindy Royal
 
Bringing Digital Into the Curriculum - AEJMC 2017
Bringing Digital Into the Curriculum - AEJMC 2017Bringing Digital Into the Curriculum - AEJMC 2017
Bringing Digital Into the Curriculum - AEJMC 2017Cindy Royal
 
Responsive Design
Responsive DesignResponsive Design
Responsive DesignCindy Royal
 
The World of Web Development - 2017
The World of Web Development - 2017The World of Web Development - 2017
The World of Web Development - 2017Cindy Royal
 
Why Should Communicators Learn to Code?
Why Should Communicators Learn to Code?Why Should Communicators Learn to Code?
Why Should Communicators Learn to Code?Cindy Royal
 
Engaging Audiences with Social Media
Engaging Audiences with Social MediaEngaging Audiences with Social Media
Engaging Audiences with Social MediaCindy Royal
 

Mehr von Cindy Royal (20)

PhDigital 2020: Web Development
PhDigital 2020: Web DevelopmentPhDigital 2020: Web Development
PhDigital 2020: Web Development
 
Redefining Doctoral Education: Preparing Future Faculty to Lead Emerging Med...
Redefining Doctoral Education:  Preparing Future Faculty to Lead Emerging Med...Redefining Doctoral Education:  Preparing Future Faculty to Lead Emerging Med...
Redefining Doctoral Education: Preparing Future Faculty to Lead Emerging Med...
 
Web Development
Web DevelopmentWeb Development
Web Development
 
Product Management
Product ManagementProduct Management
Product Management
 
Digital Product Management
Digital Product ManagementDigital Product Management
Digital Product Management
 
Bending, Breaking and Blending the Academy
Bending, Breaking and Blending the AcademyBending, Breaking and Blending the Academy
Bending, Breaking and Blending the Academy
 
Taking Control of Social Media For Your Career
Taking Control of Social Media For Your CareerTaking Control of Social Media For Your Career
Taking Control of Social Media For Your Career
 
Bootstrap Web Development Framework
Bootstrap Web Development FrameworkBootstrap Web Development Framework
Bootstrap Web Development Framework
 
Web Development Intro
Web Development IntroWeb Development Intro
Web Development Intro
 
PhDigital Bootcamp: Web Development Concepts
PhDigital Bootcamp: Web Development ConceptsPhDigital Bootcamp: Web Development Concepts
PhDigital Bootcamp: Web Development Concepts
 
PhDigital Bootcamp: Digital Product Management
PhDigital Bootcamp: Digital Product ManagementPhDigital Bootcamp: Digital Product Management
PhDigital Bootcamp: Digital Product Management
 
Digital and Social Certifications
Digital and Social CertificationsDigital and Social Certifications
Digital and Social Certifications
 
MiLab Presentation 2018
MiLab Presentation 2018MiLab Presentation 2018
MiLab Presentation 2018
 
Is Your Curriculum Digital Enough?
Is Your Curriculum Digital Enough?Is Your Curriculum Digital Enough?
Is Your Curriculum Digital Enough?
 
Fundamentals of Digital/Online Media
Fundamentals of Digital/Online MediaFundamentals of Digital/Online Media
Fundamentals of Digital/Online Media
 
Bringing Digital Into the Curriculum - AEJMC 2017
Bringing Digital Into the Curriculum - AEJMC 2017Bringing Digital Into the Curriculum - AEJMC 2017
Bringing Digital Into the Curriculum - AEJMC 2017
 
Responsive Design
Responsive DesignResponsive Design
Responsive Design
 
The World of Web Development - 2017
The World of Web Development - 2017The World of Web Development - 2017
The World of Web Development - 2017
 
Why Should Communicators Learn to Code?
Why Should Communicators Learn to Code?Why Should Communicators Learn to Code?
Why Should Communicators Learn to Code?
 
Engaging Audiences with Social Media
Engaging Audiences with Social MediaEngaging Audiences with Social Media
Engaging Audiences with Social Media
 

Kürzlich hochgeladen

Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 

Kürzlich hochgeladen (20)

Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 

Intro to Programming for Communicators - Hacks/Hackers ATX

  • 1. Intro  to  Programming  for  Communicators   Cindy  Royal,  cindyroyal.com   Hacks/Hackers     Online  News  Association     slideshare.net/cindyroyal   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.     Save  your  files  with  a  .html  extension  (any  name  is  fine,  something  like   javascript.html).  We  won’t  be  covering  HTML,  but  we  will  be  opening  the  html  file   that  includes  the  JavaScript  in  the  browser.       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  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.selectedIndex].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!