SlideShare a Scribd company logo
1 of 23
JAVASCRIPT:
   an introduction
What is JavaScript?
        JavaScript

        It adds interactivity to a Web page;
        It is combined with CSS to manipulate a Web page;
        It is a client-side language, which runs in a client
         software (browser ) that the viewer is using, rather than
         on a server;
        It is a scripting language (doesn’t require a compiling
         language to compile the codes before it runs);
        It is case-sensitive.

                                                                     2
Code View:




       <script type=“text/javascript”>
       …
       …
       </script>


                                         3
Where, how?
 1. Inline – scripts only in <body>

     <html>
     <head>
      <title>JavaScript Blueprint</title>
     </head>
     <body>
      <script type="text/javascript">
          document.write('<h2>Hello World!</h2>');
      </script>
     </body>
     </html>                                         4
Where, how?
 2. Internal – scripts in <head>, called in <body>


     <html>
      <head>
        <title> Welcome</title>
        <script type="text/javascript">
         document.write(“Hello World!”);
        </script>
      </head>

      <body onload = document.write>
      </body>
     </html>                                         5
Where, how?
  3. External – scripts saved as .js, called in .html
            Inline:                                   External:
                                         The .html file
<html>                                     <html>
 <head>                                    <head>
   <title>JavaScript Inline</title>          <title>JavaScript External</title>
 </head>                                   </head>
                                            <body>
 <body>                                       <script type= "text/javascript”
                                            src=“myjs.js”>
  <script type="text/javascript">
                                              </script>
    document.write('Hello World!');        </body>
  </script>                                </html>
 </body>
</html>
                                           The .js file

                                           document.write('Hello World!');        6
JavaScript Statements

   A JavaScript statement is a command to a browser. The
   purpose of the command is to tell the browser what to do.

   <script type="text/javascript">

     document.write("<h1>This is a heading</h1>");

     document.write("<p>This is a paragraph.</p>");

     document.write("<p>This is another paragraph.</p>");

   </script>
                                                               7
JavaScript Comments




    Comments      can be added to explain the JavaScript.
    Single   line comments start with //.
    Multi    line comments start with /* and end with */




                                                             8
Variables
                               Example
Declare/Assign Variables <html>
                          <head>
 Case   sensitive         <title>Variable example</title>
 Must   begin with a     </head>

  letter or _ or $.       <body>
 Onlycontain letters,      <script type="text/javascript">
                             var num1,num2,addnum;
  numbers, $, and _          num1=3;
 No                         num2=7;
     blank space in
                             addnum=num1+num2;
  between                    document.write("This is the result: "
 Avoid
                                +addnum+ ". <br />");
       reserved             </script>
  keywords                </body>                                9
                         </html>
Variable Types

 Booleans
  Boolean values are logical values that are either true or false, with 1
  representing true and 0 representing false.
    var john=true; or var john=1;
    var george=false; or var george=0;
 Number
     var paycheck=1200;
 Strings
   A string variable represents a string of text. It may contain letters,
   words, spaces, numbers, symbols, or anything you define. Used
   between quotation marks.
     var str1= “Big Brown Station Wagon”;
     var str2= “349875”;                                               10
Special JavaScript Characters


        Output Character        Special Code to Use
        Backslash ()                      
        Double quote (“)                   ”
        Single quote (‘)                   ’
        New line                        <br />
        Carriage return                    r
        Tab                                t
        Vertical tab                       v
        Backspace                          b
                                                      11
If statement


     ifstatement - use this statement to execute
      some code only if a specified condition is true
     if...else
              statement - use this statement to
      execute some code if the condition is true and
      another code if the condition is false
     if...elseif....else statement - use this statement
      to select one of many blocks of code to be
      executed
                                                           12
If statement

 Syntax
  if (condition1)
    {code to be executed if condition1 is true};
  else if (condition2)
    {code to be executed if condition2 is true};
  else
    {code to be executed if condition1 and condition2 are
  not true};


                                                        13
If statement example
      <script type="text/javascript">
        var x=10;
        var y=20;
        if (x>y)
        {
           document.write(“x is greater than y.<br />”);
        }
        else if (x<y)
        {
           document.write(“x is smaller than y.<br />”);
        }
        else
        {
           document.write(“x is equal to y.<br />");
        }                                                  14
      </script>
For Loop

 The for loop is used when you know in advance how many times
 the script should run.

   Syntax
   var=startvalue;
   for (var=startvalue; var<=endvalue;
     var=var+increment)
     {
     code to be executed;
     }
                                                                15
For Loop Example

   <html>
     <body>
       <script type="text/javascript">
         var i=0;
         for (i=0;i<=5;i++)
         {
          document.write("The number is " + i);
          document.write(“. <br />");
          }
       </script>
     </body>
                                                  16
   </html>
While Loop


   Syntax
   var=startvalue;
   while (var<=endvalue)
     {
      code to be executed;
     variable increment;
     }




                             17
While Loop example

   <html>
    <body>
      <script type="text/javascript">
      var i=0;
      while (i<=5)
      {
      document.write("The number is " + i + “.<br />" );
      i++;
      }
      </script>
    </body>
                                                           18
   </html>
Functions
    Can be in the head or the body section
    Repeated steps stored in the Web browser’s memory, and
     need to be called in order to execute
    Can be called multiple times with different variables



 Syntax                                 Example

function funname(var1, var2)    function myprint(message)
  {                               {
  function code;                  document.write(message);
  }                               }
                                 
Funname(var1, var2);            myprint("Hello world!");
                                                              19
Function examples

    function caltax(num1)
       { var tax=0.0875;
         total = num1+(num1*tax);
         document.write("The total is $" + total + ".");
       }
     caltax(100);

    function caltax(num1)
      { var tax=0.0875;
         total = num1+(num1*tax);
         return total;
      }
    document.write ("The total is $" + caltax(100)+ “.”);   20
Comparison Operators


   Operator                  Description                     Example

     ==       is equal to                            x==8 is false

                                                     x===5 is true
     ===      is exactly equal to (value and type)
                                                     x==="5" is false

      !=      is not equal                           x!=8 is true

      >       is greater than                        x>8 is false

      <       is less than                           x<8 is true

     >=       is greater than or equal to            x>=8 is false

     <=       is less than or equal to               x<=8 is true
                                                                        21
Logical Operators


     • Logical operators are used to determine the logic
       between variables or values.
     • Given that x=6 and y=3, the table below explains the
       logical operators:

          Operator Description             Example

            &&          and      (x < 10 && y > 1) is true
             ||          or      (x==5 || y==5) is false
              !         not      !(x==y) is true


                                                              22
Works Cited




     Most of the information on this PowerPoint are based
     on W3Schools Online Web Tutorials JavaScript section.




                                                             23

More Related Content

What's hot

10. session 10 loops and arrays
10. session 10   loops and arrays10. session 10   loops and arrays
10. session 10 loops and arraysPhúc Đỗ
 
JavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJamshid Hashimi
 
Basics java scripts
Basics java scriptsBasics java scripts
Basics java scriptsch samaram
 
Jscript Fundamentals
Jscript FundamentalsJscript Fundamentals
Jscript Fundamentalsrspaike
 
FYBSC IT Web Programming Unit III Core Javascript
FYBSC IT Web Programming Unit III  Core JavascriptFYBSC IT Web Programming Unit III  Core Javascript
FYBSC IT Web Programming Unit III Core JavascriptArti Parab Academics
 
Javascript conditional statements 1
Javascript conditional statements 1Javascript conditional statements 1
Javascript conditional statements 1Jesus Obenita Jr.
 
Intro to Programming for Communicators - Hacks/Hackers ATX
Intro to Programming for Communicators - Hacks/Hackers ATXIntro to Programming for Communicators - Hacks/Hackers ATX
Intro to Programming for Communicators - Hacks/Hackers ATXCindy Royal
 
Introduction to web programming with JavaScript
Introduction to web programming with JavaScriptIntroduction to web programming with JavaScript
Introduction to web programming with JavaScriptT11 Sessions
 
JavaScript Conditional Statements
JavaScript Conditional StatementsJavaScript Conditional Statements
JavaScript Conditional StatementsMarlon Jamera
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...Doug Jones
 

What's hot (20)

Javascript
JavascriptJavascript
Javascript
 
10. session 10 loops and arrays
10. session 10   loops and arrays10. session 10   loops and arrays
10. session 10 loops and arrays
 
JavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQuery
 
Basics java scripts
Basics java scriptsBasics java scripts
Basics java scripts
 
Jscript Fundamentals
Jscript FundamentalsJscript Fundamentals
Jscript Fundamentals
 
Wt unit 2 ppts client side technology
Wt unit 2 ppts client side technologyWt unit 2 ppts client side technology
Wt unit 2 ppts client side technology
 
JavaScript
JavaScriptJavaScript
JavaScript
 
FYBSC IT Web Programming Unit III Core Javascript
FYBSC IT Web Programming Unit III  Core JavascriptFYBSC IT Web Programming Unit III  Core Javascript
FYBSC IT Web Programming Unit III Core Javascript
 
Javascript tutorial
Javascript tutorialJavascript tutorial
Javascript tutorial
 
Javascript
JavascriptJavascript
Javascript
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
 
Javascript conditional statements 1
Javascript conditional statements 1Javascript conditional statements 1
Javascript conditional statements 1
 
Java script
Java scriptJava script
Java script
 
Intro to Programming for Communicators - Hacks/Hackers ATX
Intro to Programming for Communicators - Hacks/Hackers ATXIntro to Programming for Communicators - Hacks/Hackers ATX
Intro to Programming for Communicators - Hacks/Hackers ATX
 
Introduction to web programming with JavaScript
Introduction to web programming with JavaScriptIntroduction to web programming with JavaScript
Introduction to web programming with JavaScript
 
Java script
Java scriptJava script
Java script
 
JavaScript Conditional Statements
JavaScript Conditional StatementsJavaScript Conditional Statements
JavaScript Conditional Statements
 
Java script
Java scriptJava script
Java script
 
Javascript
JavascriptJavascript
Javascript
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
 

Viewers also liked

Week1 Dreamweaver and Server
Week1 Dreamweaver and ServerWeek1 Dreamweaver and Server
Week1 Dreamweaver and ServerRowena LI
 
Week1 Introduction
Week1 IntroductionWeek1 Introduction
Week1 IntroductionRowena LI
 
Week 2 HTML lists, hyperlinks, tables, and images
Week 2 HTML lists, hyperlinks, tables, and imagesWeek 2 HTML lists, hyperlinks, tables, and images
Week 2 HTML lists, hyperlinks, tables, and imagesRowena LI
 
Week5 ap forms
Week5 ap formsWeek5 ap forms
Week5 ap formsRowena LI
 
Social and Mobile Media in the Librarian Profession
Social and Mobile Media in the Librarian ProfessionSocial and Mobile Media in the Librarian Profession
Social and Mobile Media in the Librarian ProfessionRowena LI
 
Social media as a widget
Social media as a widgetSocial media as a widget
Social media as a widgetRowena LI
 
Week7 Dreamweaver Behavior & Image Hotspots
Week7 Dreamweaver Behavior & Image HotspotsWeek7 Dreamweaver Behavior & Image Hotspots
Week7 Dreamweaver Behavior & Image HotspotsRowena LI
 
Hybrid in 5 minutes
Hybrid in 5 minutesHybrid in 5 minutes
Hybrid in 5 minutesRowena LI
 
Web 2.0: its impact on library services
Web 2.0: its impact on library servicesWeb 2.0: its impact on library services
Web 2.0: its impact on library servicesRowena LI
 
Renew OnDemand Cloud Application
Renew OnDemand Cloud ApplicationRenew OnDemand Cloud Application
Renew OnDemand Cloud ApplicationServiceSource
 
Transitioning to a subscription business model
Transitioning to a subscription business modelTransitioning to a subscription business model
Transitioning to a subscription business modelServiceSource
 
Dreamforce 13: Engage with Intelligence to Retain for Life
Dreamforce 13: Engage with Intelligence to Retain for LifeDreamforce 13: Engage with Intelligence to Retain for Life
Dreamforce 13: Engage with Intelligence to Retain for LifeServiceSource
 
Tribe Night Slidshare Presentation
Tribe Night Slidshare PresentationTribe Night Slidshare Presentation
Tribe Night Slidshare PresentationTribe Church
 
Capture More Recurring Revenue
Capture More Recurring RevenueCapture More Recurring Revenue
Capture More Recurring RevenueServiceSource
 
3 Findings that Can Get Your Customer Revenue Back on the Path to Growth [Inf...
3 Findings that Can Get Your Customer Revenue Back on the Path to Growth [Inf...3 Findings that Can Get Your Customer Revenue Back on the Path to Growth [Inf...
3 Findings that Can Get Your Customer Revenue Back on the Path to Growth [Inf...ServiceSource
 
Keebee/Keeping Kids Busy presentation april 2009
Keebee/Keeping Kids Busy presentation april 2009Keebee/Keeping Kids Busy presentation april 2009
Keebee/Keeping Kids Busy presentation april 2009Keeping_Kids_Busy
 

Viewers also liked (20)

Week1 Dreamweaver and Server
Week1 Dreamweaver and ServerWeek1 Dreamweaver and Server
Week1 Dreamweaver and Server
 
Week1 Introduction
Week1 IntroductionWeek1 Introduction
Week1 Introduction
 
Week 2 HTML lists, hyperlinks, tables, and images
Week 2 HTML lists, hyperlinks, tables, and imagesWeek 2 HTML lists, hyperlinks, tables, and images
Week 2 HTML lists, hyperlinks, tables, and images
 
Week3 css
Week3 cssWeek3 css
Week3 css
 
PHP
PHPPHP
PHP
 
Week5 ap forms
Week5 ap formsWeek5 ap forms
Week5 ap forms
 
Social and Mobile Media in the Librarian Profession
Social and Mobile Media in the Librarian ProfessionSocial and Mobile Media in the Librarian Profession
Social and Mobile Media in the Librarian Profession
 
Social media as a widget
Social media as a widgetSocial media as a widget
Social media as a widget
 
Week7 Dreamweaver Behavior & Image Hotspots
Week7 Dreamweaver Behavior & Image HotspotsWeek7 Dreamweaver Behavior & Image Hotspots
Week7 Dreamweaver Behavior & Image Hotspots
 
Hybrid in 5 minutes
Hybrid in 5 minutesHybrid in 5 minutes
Hybrid in 5 minutes
 
Web 2.0: its impact on library services
Web 2.0: its impact on library servicesWeb 2.0: its impact on library services
Web 2.0: its impact on library services
 
Week 2
Week 2Week 2
Week 2
 
Renew OnDemand Cloud Application
Renew OnDemand Cloud ApplicationRenew OnDemand Cloud Application
Renew OnDemand Cloud Application
 
Transitioning to a subscription business model
Transitioning to a subscription business modelTransitioning to a subscription business model
Transitioning to a subscription business model
 
Dreamforce 13: Engage with Intelligence to Retain for Life
Dreamforce 13: Engage with Intelligence to Retain for LifeDreamforce 13: Engage with Intelligence to Retain for Life
Dreamforce 13: Engage with Intelligence to Retain for Life
 
Tribe Night Slidshare Presentation
Tribe Night Slidshare PresentationTribe Night Slidshare Presentation
Tribe Night Slidshare Presentation
 
Capture More Recurring Revenue
Capture More Recurring RevenueCapture More Recurring Revenue
Capture More Recurring Revenue
 
Trabajo de majo
Trabajo de majoTrabajo de majo
Trabajo de majo
 
3 Findings that Can Get Your Customer Revenue Back on the Path to Growth [Inf...
3 Findings that Can Get Your Customer Revenue Back on the Path to Growth [Inf...3 Findings that Can Get Your Customer Revenue Back on the Path to Growth [Inf...
3 Findings that Can Get Your Customer Revenue Back on the Path to Growth [Inf...
 
Keebee/Keeping Kids Busy presentation april 2009
Keebee/Keeping Kids Busy presentation april 2009Keebee/Keeping Kids Busy presentation april 2009
Keebee/Keeping Kids Busy presentation april 2009
 

Similar to JavaScript

Similar to JavaScript (20)

Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java script
 
Java scripts
Java scriptsJava scripts
Java scripts
 
Unit 2.4
Unit 2.4Unit 2.4
Unit 2.4
 
Unit 2.4
Unit 2.4Unit 2.4
Unit 2.4
 
Javascript
JavascriptJavascript
Javascript
 
Java script
Java scriptJava script
Java script
 
Java script
Java scriptJava script
Java script
 
Javascript1
Javascript1Javascript1
Javascript1
 
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
 
Introduction of javascript
Introduction of javascriptIntroduction of javascript
Introduction of javascript
 
1. java script language fundamentals
1. java script language fundamentals1. java script language fundamentals
1. java script language fundamentals
 
Js mod1
Js mod1Js mod1
Js mod1
 
Java script Learn Easy
Java script Learn Easy Java script Learn Easy
Java script Learn Easy
 
Java script
Java scriptJava script
Java script
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
Intro to Programming for Communicators - Hacks/Hackers ATX
Intro to Programming for Communicators - Hacks/Hackers ATXIntro to Programming for Communicators - Hacks/Hackers ATX
Intro to Programming for Communicators - Hacks/Hackers ATX
 
FYBSC IT Web Programming Unit IV PHP and MySQL
FYBSC IT Web Programming Unit IV  PHP and MySQLFYBSC IT Web Programming Unit IV  PHP and MySQL
FYBSC IT Web Programming Unit IV PHP and MySQL
 
BITM3730 10-17.pptx
BITM3730 10-17.pptxBITM3730 10-17.pptx
BITM3730 10-17.pptx
 
Wt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technologyWt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technology
 
JavaScript Training
JavaScript TrainingJavaScript Training
JavaScript Training
 

Recently uploaded

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 

Recently uploaded (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 

JavaScript

  • 1. JAVASCRIPT: an introduction
  • 2. What is JavaScript? JavaScript  It adds interactivity to a Web page;  It is combined with CSS to manipulate a Web page;  It is a client-side language, which runs in a client software (browser ) that the viewer is using, rather than on a server;  It is a scripting language (doesn’t require a compiling language to compile the codes before it runs);  It is case-sensitive. 2
  • 3. Code View: <script type=“text/javascript”> … … </script> 3
  • 4. Where, how? 1. Inline – scripts only in <body> <html> <head> <title>JavaScript Blueprint</title> </head> <body> <script type="text/javascript"> document.write('<h2>Hello World!</h2>'); </script> </body> </html> 4
  • 5. Where, how? 2. Internal – scripts in <head>, called in <body> <html> <head> <title> Welcome</title> <script type="text/javascript"> document.write(“Hello World!”); </script> </head> <body onload = document.write> </body> </html> 5
  • 6. Where, how? 3. External – scripts saved as .js, called in .html Inline: External: The .html file <html> <html> <head> <head> <title>JavaScript Inline</title> <title>JavaScript External</title> </head> </head> <body> <body> <script type= "text/javascript” src=“myjs.js”> <script type="text/javascript"> </script> document.write('Hello World!'); </body> </script> </html> </body> </html> The .js file document.write('Hello World!'); 6
  • 7. JavaScript Statements A JavaScript statement is a command to a browser. The purpose of the command is to tell the browser what to do. <script type="text/javascript"> document.write("<h1>This is a heading</h1>"); document.write("<p>This is a paragraph.</p>"); document.write("<p>This is another paragraph.</p>"); </script> 7
  • 8. JavaScript Comments  Comments can be added to explain the JavaScript.  Single line comments start with //.  Multi line comments start with /* and end with */ 8
  • 9. Variables Example Declare/Assign Variables <html> <head>  Case sensitive <title>Variable example</title>  Must begin with a </head> letter or _ or $. <body>  Onlycontain letters, <script type="text/javascript"> var num1,num2,addnum; numbers, $, and _ num1=3;  No num2=7; blank space in addnum=num1+num2; between document.write("This is the result: "  Avoid +addnum+ ". <br />"); reserved </script> keywords </body> 9 </html>
  • 10. Variable Types Booleans Boolean values are logical values that are either true or false, with 1 representing true and 0 representing false. var john=true; or var john=1; var george=false; or var george=0; Number var paycheck=1200; Strings A string variable represents a string of text. It may contain letters, words, spaces, numbers, symbols, or anything you define. Used between quotation marks. var str1= “Big Brown Station Wagon”; var str2= “349875”; 10
  • 11. Special JavaScript Characters Output Character Special Code to Use Backslash () Double quote (“) ” Single quote (‘) ’ New line <br /> Carriage return r Tab t Vertical tab v Backspace b 11
  • 12. If statement  ifstatement - use this statement to execute some code only if a specified condition is true  if...else statement - use this statement to execute some code if the condition is true and another code if the condition is false  if...elseif....else statement - use this statement to select one of many blocks of code to be executed 12
  • 13. If statement Syntax if (condition1)   {code to be executed if condition1 is true}; else if (condition2)   {code to be executed if condition2 is true}; else   {code to be executed if condition1 and condition2 are not true}; 13
  • 14. If statement example <script type="text/javascript"> var x=10; var y=20; if (x>y) { document.write(“x is greater than y.<br />”); } else if (x<y) { document.write(“x is smaller than y.<br />”); } else { document.write(“x is equal to y.<br />"); } 14 </script>
  • 15. For Loop The for loop is used when you know in advance how many times the script should run. Syntax var=startvalue; for (var=startvalue; var<=endvalue; var=var+increment) { code to be executed; } 15
  • 16. For Loop Example <html> <body> <script type="text/javascript"> var i=0; for (i=0;i<=5;i++) { document.write("The number is " + i); document.write(“. <br />"); } </script> </body> 16 </html>
  • 17. While Loop Syntax var=startvalue; while (var<=endvalue) {  code to be executed; variable increment; } 17
  • 18. While Loop example <html> <body> <script type="text/javascript"> var i=0; while (i<=5)   {   document.write("The number is " + i + “.<br />" );   i++;   } </script> </body> 18 </html>
  • 19. Functions  Can be in the head or the body section  Repeated steps stored in the Web browser’s memory, and need to be called in order to execute  Can be called multiple times with different variables Syntax Example function funname(var1, var2) function myprint(message) { { function code; document.write(message); } }   Funname(var1, var2); myprint("Hello world!"); 19
  • 20. Function examples function caltax(num1) { var tax=0.0875; total = num1+(num1*tax); document.write("The total is $" + total + "."); }  caltax(100); function caltax(num1) { var tax=0.0875; total = num1+(num1*tax); return total; } document.write ("The total is $" + caltax(100)+ “.”); 20
  • 21. Comparison Operators Operator Description Example == is equal to x==8 is false x===5 is true === is exactly equal to (value and type) x==="5" is false != is not equal x!=8 is true > is greater than x>8 is false < is less than x<8 is true >= is greater than or equal to x>=8 is false <= is less than or equal to x<=8 is true 21
  • 22. Logical Operators • Logical operators are used to determine the logic between variables or values. • Given that x=6 and y=3, the table below explains the logical operators: Operator Description Example && and (x < 10 && y > 1) is true || or (x==5 || y==5) is false ! not !(x==y) is true 22
  • 23. Works Cited Most of the information on this PowerPoint are based on W3Schools Online Web Tutorials JavaScript section. 23