SlideShare a Scribd company logo
Introduction to Java Scripting by:  Alexandra Vlachakis Sandy Creek High School, Fayette County Schools Content and Resources Used With Permission:  W3 Schools. www.w3schools.com. 12-25-11.
Lesson 1 : Introduction to Java Scripting
What is JavaScript? JavaScript is the most popular scripting language on the internet, and works in all major browsers, such as Internet Explorer, Firefox, Chrome, Opera, and Safari.  JavaScript was designed to add interactivity to HTML pages  Before you start this lesson you should already know HTML
What is JavaScript?  JavaScript is a scripting language  A scripting language is a lightweight programming language  JavaScript is usually embedded directly into HTML pages  JavaScript is an interpreted language (means that scripts execute without preliminary compilation)  Everyone can use JavaScript without purchasing a license
Are Java and JavaScript the same?   NO!     Java and JavaScript are two completely different languages in both concept and design! Java (developed by Sun Microsystems) is a powerful and much more complex programming language - in the same category as C and C++.
What can a JavaScript do? HTML authors are normally not programmers  JavaScript is a scripting language with a very simple syntax! It makes it possible for almost anyone to put small "snippets" of code into their HTML pages  JavaScript can put dynamic text into an HTML page   
What can a JavaScript do? For example you can write a JavaScript statement like this:  document.write (&quot;<h1>&quot; + name + &quot;</h1>&quot;)   This statement can write a variable text into an HTML page    
Where can you put a JavaScript? JavaScripts in a page will be executed immediately while the page loads into the browser. This is not always what we want.  Sometimes we want to execute a script when a page loads, other times when a user triggers an event.   
Where can you put a JavaScript? Scripts can go in the <body>   Scripts to be executed when the page loads go in the body section. If you place a script in the body section, it generates the content of a page. Scripts can also go in the in <head>   Scripts to be executed when they are called, or when an event is triggered, go in the head section.   If you place a script in the head section, you will ensure that the script is loaded before anyone uses it. Scripts can also be external    If you want to run the same JavaScript on several pages, without having to write the same script on every page, you can write a JavaScript in an external file. We will talk more about this later.
Java Scripting Assignment 1 Type the following code into Notepad or Text Editor for Mac.   <html> <body> <script type=&quot;text/javascript&quot;> document.write(&quot; Hello World! &quot;); </script> </body> </html> Save your page as java1.html. When you preview it on the browser it should display: Hello World!
Let's look at that code what does it mean? We will look at each line of code individually. For example line 1 - 2 are below.  These you will remember at the beginning tags of HTML.  Note your script starts after the <body> tag in this example. <html>   <body>   The next line tells the page the type of script you will be adding. In this case it is text. <script type=&quot; text /javascript&quot;>    
More About The Code... Line 4  document.write(&quot; Hello World! &quot;); Tells the page to write the words &quot;Hello World&quot; on your webpage.   To write text in your JavaScript you need to put it in between quotes and in parenthesis  The code also states it is a  document.write  command  This the standard JavaScript command for  writing output  to a page.  By entering the  document.write  command between the  <script>  and  </script>  tags, the browser will recognize it as a JavaScript command and execute the code line.  As I mentioned for this example the browser will write  Hello World!  on the page
Closing Your Lines Of Code Line 5 is the ending tag of the script.  </script> You need to just like in HTML close your <script> when you have completed your JavaScript. Why is it important to close the <script> tag? Line 6-7 close your HTML tags <body> <html>. </body> </html>
Lesson 2 :  What Can Java Scripting Do?
What can Javascripting do? JavaScript can react to events  -  A JavaScript can be set to execute when something happens,  like when a page has finished loading or when a user clicks on an HTML element   JavaScript can read and write HTML elements  A JavaScript can read and change the content of an HTML element     JavaScript can be used to validate data  - A JavaScript can be used to validate form data before  it is submitted to a server. This saves the server from extra processing
What else can Java Scripting do? JavaScript can be used to detect the visitor's browser  A JavaScript can be used to detect the visitor's browser - load another page specifically designed for that browser   JavaScript can be used to create cookies  - A JavaScript can be used to store and retrieve  information on the visitor's computer
Lesson 3 :  Syntax & Rules for  Java Scripting
JavaScript is Case Sensitive Unlike HTML, JavaScript is case sensitive!  Therefore watch your capitalization closely  Especially when you write JavaScript for: statements  create or call variables  objects and functions  
JavaScripting and Semicolons   It is normal to add a semicolon at the end of each executable statement.   ex. document.write(&quot;Hello Dolly&quot;); Most people think this is a good programming practice, and most often you will see this in JavaScript examples on the web.
Java Scripting and Semicolons The semicolon is optional (according to the JavaScript standard), and the browser is supposed to interpret the end of the line as the end of the statement.  Because of this you will often see examples without the semicolon at the end.  Note:  Using semicolons makes it possible to write multiple statements on one line. Where else did we use semicolons to write code?
JavaScript Code JavaScript code (or just JavaScript) is a sequence of JavaScript statements. Each statement is executed by the browser in the sequence they are written. In the following example we will write a heading and two paragraphs to a web page.
Java Scripting: Syntax & Rules  Assignment 2 <script type=&quot;text/javascript&quot;>  document.write (&quot;<h1>This is a heading</h1>&quot;);  document.write (&quot;<p>This is a paragraph.</p>&quot;); document.write (&quot;<p>This is another paragraph.</p>&quot;);  </script>  Save your page as java-syntax.html.
Lesson 4 :  Java Scripting Blocks
JavaScript Blocks   JavaScript statements can be grouped together in blocks. Blocks start with a left curly bracket  { and ends with a right curly bracket  } The purpose of a block is to make the sequence of statements execute together. The following example will write a heading and two paragraphs to a web page.
Java Scripting: Blocks Assignment 3 <script type=&quot;text/javascript&quot;>  { document.write (&quot;<h1>This is a heading</h1>&quot;); document.write (&quot;<p>This is a paragraph.</p>&quot;); document.write (&quot;<p>This is another paragraph.</p>&quot;);  }  </script>  Save your file as Java-blocks.html The example above is not very useful. It just demonstrates the use of a block. Normally a block is used to group statements together in a function or in a condition (where a group of statements should be executed if a condition is met). You will learn more about functions and conditions in later chapters.
Lesson 5 :  Java Script Comments
JavaScript Comments JavaScript comments can be used to make the code more readable. Comments can be added to explain the JavaScript, or to make the code more readable. Single line comments start with //.  
Java Scripting: Comments Assignment 4   <script type=&quot;text/javascript&quot;> // Write a heading document.write (&quot;<h1>This is a heading</h1>&quot;); // Write two paragraphs document.write (&quot;<p>This is a paragraph.</p>&quot;); document.write (&quot;<p>This is another paragraph.</p>&quot;); </script>  The following example uses single line comments to explain the code they will not show up when displayed in  the browser: Save your file as  Java-comments.html
Lesson 6 :  Java Scripting Variables
Algebra Basics Do you remember algebra class?  x=5, y=6, z=x+y Do you remember that a letter (like x) could be used to hold a value (like 5), and that you could use the information above to calculate the value of z to be 11? These letters are called variables, and variables can be used to hold values (x=5) or expressions (z=x+y).
JavaScript Variables  As with algebra, JavaScript variables are used to hold values or expressions. A variable can have a short name, like x, or a more descriptive name, like “ car name ”.
Rules for JavaScript  variable names: Variable names are case sensitive  (y and Y are two different variables) Variable names must begin with a letter or the underscore character Note:  Because JavaScript is case sensitive, variable names are case sensitive.
Java Scripting: Variables Assignment 5   Type the following code into a new notepad document <html> <body> <script type=&quot;text/javascript&quot;> var firstname; firstname=&quot;Hege&quot;; document.write(firstname); document.write(&quot;<br />&quot;); firstname=&quot;Tove&quot;; document.write(firstname);  </script> <p>The script above declares a variable, assigns a value to it, displays the value, changes the value, and displays the value again.</p> </body> </html> Save your file as Java-variables.html
Lesson 7 :  Java Scripting Conditional Statements
Conditional Statements Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this.   In JavaScript we have the following conditional statements: if statement   - 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...else if....else statement  - use this statement to select one of many blocks of code to be executed switch statement   - use this statement to select one of many blocks of code to be executed
If statements Use the ‘ if ’  statement to execute some code only if a specified condition is true.   Syntax   if  ( condition )   {   code to be executed if condition is true   }  Note that ‘ if ’ is written in lowercase letters. Using uppercase letters ( IF ) will generate a JavaScript error!
Type the following code: <script type=&quot;text/javascript&quot;> //Write a &quot;Good morning&quot; greeting if //the time is less than 10 var d=new Date(); var time=d.getHours(); if (time<10)   {   document.write(&quot;<b>Good morning</b>&quot;);   } </script>   Save your file as  Java-if.html. Change the time and refresh your browser and see what happens. Java Scripting: If Statement Assignment 6 Note that there is no  ‘else’  in this syntax. You tell the browser to execute some code  only if the specified condition is true .
If...else Statements   Use the  if....else  statement to execute some code if a condition is true and another code if the condition is not true. Syntax  if  (condition)   {   code to be executed if condition is true   } else   {   code to be executed if condition is not true   }
Type the following code: <script type=&quot;text/javascript&quot;>  //write a &quot;Good morning&quot; greeting if //the time is less than 14 var d=new Date(); var time=d.getHours(); if (time<14) { document.write(&quot;<b>Good afternoon</b>&quot;); } else { document.write(&quot;<b>Good evening</b>&quot;); } Save your file as  Java-if-else.html Change the time and refresh your browser and see what happens. Java Scripting:  If Else Statement Assignment 7
If...else if...else Statement   Use the  if....else if...else  statement to select one of several blocks of code to be executed. 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   }
Java Scripting:  If Statement else Assignment 8 <script type=&quot;text/javascript&quot;> var d = new Date() var time = d.getHours() if (time<10)   {   document.write(&quot;<b>Good morning</b>&quot;);   } else if (time>10 && time<16)   {   document.write(&quot;<b>Good day</b>&quot;);   } else   {   document.write(&quot;<b>Hello World!</b>&quot;);   } </script> Save your file as  ,  Java-if –else-else.html Change the time and refresh your browser and see what happens.
Java Scripting:  Switch Conditional Statements Assignment 9 <html> <body> <script type=&quot;text/javascript&quot;> var r=Math.random(); if (r>0.5) { document.write(&quot;<a href='http:// www.w3.org/  '>W3</a>&quot;); } else { document.write(&quot;<a href='http://www.sandycreekhighschool.com'>Sandy Creek High School</a>&quot;); } </script> </body> </html> *In this example you have a 50/50 chance of getting one or the other link. Save your file as  Java-switch.html  Change the time and refresh your browser and see what happens.
Culminating Performance Task Make it Snow Web Page Students will create a  page that allows it to snow (see example). Students can personalize the page by adding content, colors, and their own version of snow like leaves or footballs. Students can present the page to the class.

More Related Content

What's hot (20)

Android Architecture
Android ArchitectureAndroid Architecture
Android Architecture
deepakshare
 
JavaScript
JavaScriptJavaScript
JavaScript
Vidyut Singhania
 
Flutter
FlutterFlutter
Flutter
Ankit Kumar
 
Angularjs PPT
Angularjs PPTAngularjs PPT
Angularjs PPT
Amit Baghel
 
CSS
CSSCSS
CSS
Vladimir Zhidal
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
Amit Tyagi
 
React JS - A quick introduction tutorial
React JS - A quick introduction tutorialReact JS - A quick introduction tutorial
React JS - A quick introduction tutorial
Mohammed Fazuluddin
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
Lohith Goudagere Nagaraj
 
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Steve Pember
 
CSS
CSSCSS
CSS
People Strategists
 
Android report
Android reportAndroid report
Android report
blogger at indiandswad
 
Introduction to HTML
Introduction to HTMLIntroduction to HTML
Introduction to HTML
Seble Nigussie
 
Angular Basics.pptx
Angular Basics.pptxAngular Basics.pptx
Angular Basics.pptx
AshokKumar616995
 
Presentation on "An Introduction to ReactJS"
Presentation on "An Introduction to ReactJS"Presentation on "An Introduction to ReactJS"
Presentation on "An Introduction to ReactJS"
Flipkart
 
Introduzione ad angular 7/8
Introduzione ad angular 7/8Introduzione ad angular 7/8
Introduzione ad angular 7/8
Valerio Radice
 
JSON and XML
JSON and XMLJSON and XML
JSON and XML
People Strategists
 
React JS part 1
React JS part 1React JS part 1
React JS part 1
Diluka Wittahachchige
 
RxJS - The Basics & The Future
RxJS - The Basics & The FutureRxJS - The Basics & The Future
RxJS - The Basics & The Future
Tracy Lee
 
React js for beginners
React js for beginnersReact js for beginners
React js for beginners
Alessandro Valenti
 
Understanding react hooks
Understanding react hooksUnderstanding react hooks
Understanding react hooks
Samundra khatri
 

Viewers also liked (18)

Unit 1-uses for scripting languages,web scripting
Unit 1-uses for scripting languages,web scriptingUnit 1-uses for scripting languages,web scripting
Unit 1-uses for scripting languages,web scripting
sana mateen
 
Unit 1-introduction to scripts
Unit 1-introduction to scriptsUnit 1-introduction to scripts
Unit 1-introduction to scripts
sana mateen
 
Automation test scripting guidelines
Automation test scripting guidelines Automation test scripting guidelines
Automation test scripting guidelines
Bharathi Krishnamurthi
 
An Seo’s Intro to Web Dev, HTML, CSS and JavaScript
An Seo’s Intro to Web Dev, HTML, CSS and JavaScriptAn Seo’s Intro to Web Dev, HTML, CSS and JavaScript
An Seo’s Intro to Web Dev, HTML, CSS and JavaScript
Troyfawkes
 
Tugas Pw [6]
Tugas Pw [6]Tugas Pw [6]
Tugas Pw [6]
guestca37172
 
Add a web server
Add a web serverAdd a web server
Add a web server
AgCharu
 
ServiceNow Knowledge11 Advanced Scripting & Debugging Lab
ServiceNow Knowledge11 Advanced Scripting & Debugging LabServiceNow Knowledge11 Advanced Scripting & Debugging Lab
ServiceNow Knowledge11 Advanced Scripting & Debugging Lab
John Roberts
 
JavaScript: Operators and Expressions
JavaScript: Operators and ExpressionsJavaScript: Operators and Expressions
JavaScript: Operators and Expressions
LearnNowOnline
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programming
Cavite National Science High School
 
ISDN & DSL
ISDN & DSLISDN & DSL
ISDN & DSL
Umair Arain
 
How to Design a Successful Test Automation Strategy
How to Design a Successful Test Automation Strategy How to Design a Successful Test Automation Strategy
How to Design a Successful Test Automation Strategy
Impetus Technologies
 
Web servers
Web serversWeb servers
Web servers
webhostingguy
 
Web servers
Web serversWeb servers
Web servers
Kuldeep Kulkarni
 
Presentation about servers
Presentation about serversPresentation about servers
Presentation about servers
Sasin Prabu
 
Basic Server PPT (THDC)
Basic Server PPT (THDC)Basic Server PPT (THDC)
Basic Server PPT (THDC)
Vineet Pokhriyal
 
Types of Servers - Basic Differences
Types of Servers - Basic DifferencesTypes of Servers - Basic Differences
Types of Servers - Basic Differences
VR Talsaniya
 
Web Servers (ppt)
Web Servers (ppt)Web Servers (ppt)
Web Servers (ppt)
webhostingguy
 
How to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheHow to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your Niche
Leslie Samuel
 
Unit 1-uses for scripting languages,web scripting
Unit 1-uses for scripting languages,web scriptingUnit 1-uses for scripting languages,web scripting
Unit 1-uses for scripting languages,web scripting
sana mateen
 
Unit 1-introduction to scripts
Unit 1-introduction to scriptsUnit 1-introduction to scripts
Unit 1-introduction to scripts
sana mateen
 
An Seo’s Intro to Web Dev, HTML, CSS and JavaScript
An Seo’s Intro to Web Dev, HTML, CSS and JavaScriptAn Seo’s Intro to Web Dev, HTML, CSS and JavaScript
An Seo’s Intro to Web Dev, HTML, CSS and JavaScript
Troyfawkes
 
Add a web server
Add a web serverAdd a web server
Add a web server
AgCharu
 
ServiceNow Knowledge11 Advanced Scripting & Debugging Lab
ServiceNow Knowledge11 Advanced Scripting & Debugging LabServiceNow Knowledge11 Advanced Scripting & Debugging Lab
ServiceNow Knowledge11 Advanced Scripting & Debugging Lab
John Roberts
 
JavaScript: Operators and Expressions
JavaScript: Operators and ExpressionsJavaScript: Operators and Expressions
JavaScript: Operators and Expressions
LearnNowOnline
 
How to Design a Successful Test Automation Strategy
How to Design a Successful Test Automation Strategy How to Design a Successful Test Automation Strategy
How to Design a Successful Test Automation Strategy
Impetus Technologies
 
Presentation about servers
Presentation about serversPresentation about servers
Presentation about servers
Sasin Prabu
 
Types of Servers - Basic Differences
Types of Servers - Basic DifferencesTypes of Servers - Basic Differences
Types of Servers - Basic Differences
VR Talsaniya
 
How to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheHow to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your Niche
Leslie Samuel
 
Ad

Similar to Introduction to Java Scripting (20)

Javascript survival for CSBN Sophomores
Javascript survival for CSBN SophomoresJavascript survival for CSBN Sophomores
Javascript survival for CSBN Sophomores
Andy de Vera
 
Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
DHTMLExtreme
 
Javascript
JavascriptJavascript
Javascript
Sushma M
 
Basics java scripts
Basics java scriptsBasics java scripts
Basics java scripts
ch samaram
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java script
nanjil1984
 
JavaScript_III.pptx
JavaScript_III.pptxJavaScript_III.pptx
JavaScript_III.pptx
rashmiisrani1
 
Javascript
JavascriptJavascript
Javascript
Nagarajan
 
2javascript web programming with JAVA script
2javascript web programming with JAVA script2javascript web programming with JAVA script
2javascript web programming with JAVA script
umardanjumamaiwada
 
JS BASICS JAVA SCRIPT SCRIPTING
JS BASICS JAVA SCRIPT SCRIPTINGJS BASICS JAVA SCRIPT SCRIPTING
JS BASICS JAVA SCRIPT SCRIPTING
Arulkumar
 
JAVA SCRIPT
JAVA SCRIPTJAVA SCRIPT
JAVA SCRIPT
Go4Guru
 
Java Script
Java ScriptJava Script
Java Script
husbancom
 
Java script
Java scriptJava script
Java script
sanjay joshi
 
Java script
Java scriptJava script
Java script
umesh patil
 
java-scriptcdvcx vnbm,azsdfghjkml;sxdfcgmndxfcgvhb nmfctgvbhjnm ,cfgvb nm,xc ...
java-scriptcdvcx vnbm,azsdfghjkml;sxdfcgmndxfcgvhb nmfctgvbhjnm ,cfgvb nm,xc ...java-scriptcdvcx vnbm,azsdfghjkml;sxdfcgmndxfcgvhb nmfctgvbhjnm ,cfgvb nm,xc ...
java-scriptcdvcx vnbm,azsdfghjkml;sxdfcgmndxfcgvhb nmfctgvbhjnm ,cfgvb nm,xc ...
kavigamage62
 
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
Bhavsingh Maloth
 
Web programming UNIT II by Bhavsingh Maloth
Web programming UNIT II by Bhavsingh MalothWeb programming UNIT II by Bhavsingh Maloth
Web programming UNIT II by Bhavsingh Maloth
Bhavsingh Maloth
 
JavaScript (1).pptdffdfvdfvfvfvfefwefedfe
JavaScript (1).pptdffdfvdfvfvfvfefwefedfeJavaScript (1).pptdffdfvdfvfvfvfefwefedfe
JavaScript (1).pptdffdfvdfvfvfvfefwefedfe
sgg86953
 
8.-Javascript-report powerpoint presentation
8.-Javascript-report powerpoint presentation8.-Javascript-report powerpoint presentation
8.-Javascript-report powerpoint presentation
JohnLagman3
 
CS8651- Unit 2 - JS.internet programming paper anna university -2017 regulation
CS8651- Unit 2 - JS.internet programming paper anna university -2017 regulationCS8651- Unit 2 - JS.internet programming paper anna university -2017 regulation
CS8651- Unit 2 - JS.internet programming paper anna university -2017 regulation
amrashbhanuabdul
 
Java script
Java scriptJava script
Java script
Sukrit Gupta
 
Javascript survival for CSBN Sophomores
Javascript survival for CSBN SophomoresJavascript survival for CSBN Sophomores
Javascript survival for CSBN Sophomores
Andy de Vera
 
Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
DHTMLExtreme
 
Javascript
JavascriptJavascript
Javascript
Sushma M
 
Basics java scripts
Basics java scriptsBasics java scripts
Basics java scripts
ch samaram
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java script
nanjil1984
 
2javascript web programming with JAVA script
2javascript web programming with JAVA script2javascript web programming with JAVA script
2javascript web programming with JAVA script
umardanjumamaiwada
 
JS BASICS JAVA SCRIPT SCRIPTING
JS BASICS JAVA SCRIPT SCRIPTINGJS BASICS JAVA SCRIPT SCRIPTING
JS BASICS JAVA SCRIPT SCRIPTING
Arulkumar
 
JAVA SCRIPT
JAVA SCRIPTJAVA SCRIPT
JAVA SCRIPT
Go4Guru
 
java-scriptcdvcx vnbm,azsdfghjkml;sxdfcgmndxfcgvhb nmfctgvbhjnm ,cfgvb nm,xc ...
java-scriptcdvcx vnbm,azsdfghjkml;sxdfcgmndxfcgvhb nmfctgvbhjnm ,cfgvb nm,xc ...java-scriptcdvcx vnbm,azsdfghjkml;sxdfcgmndxfcgvhb nmfctgvbhjnm ,cfgvb nm,xc ...
java-scriptcdvcx vnbm,azsdfghjkml;sxdfcgmndxfcgvhb nmfctgvbhjnm ,cfgvb nm,xc ...
kavigamage62
 
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
Bhavsingh Maloth
 
Web programming UNIT II by Bhavsingh Maloth
Web programming UNIT II by Bhavsingh MalothWeb programming UNIT II by Bhavsingh Maloth
Web programming UNIT II by Bhavsingh Maloth
Bhavsingh Maloth
 
JavaScript (1).pptdffdfvdfvfvfvfefwefedfe
JavaScript (1).pptdffdfvdfvfvfvfefwefedfeJavaScript (1).pptdffdfvdfvfvfvfefwefedfe
JavaScript (1).pptdffdfvdfvfvfvfefwefedfe
sgg86953
 
8.-Javascript-report powerpoint presentation
8.-Javascript-report powerpoint presentation8.-Javascript-report powerpoint presentation
8.-Javascript-report powerpoint presentation
JohnLagman3
 
CS8651- Unit 2 - JS.internet programming paper anna university -2017 regulation
CS8651- Unit 2 - JS.internet programming paper anna university -2017 regulationCS8651- Unit 2 - JS.internet programming paper anna university -2017 regulation
CS8651- Unit 2 - JS.internet programming paper anna university -2017 regulation
amrashbhanuabdul
 
Ad

Recently uploaded (20)

Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptxjune 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdfFEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
National Information Standards Organization (NISO)
 
Respiratory System , Urinary System
Respiratory  System , Urinary SystemRespiratory  System , Urinary System
Respiratory System , Urinary System
RushiMandali
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
Quiz Club of PSG College of Arts & Science
 
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
Quiz Club of PSG College of Arts & Science
 
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
Quiz Club of PSG College of Arts & Science
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdfAllomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition OecdEnergy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
GeorgeDiamandis11
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptxCapitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptxjune 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdfFEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
Respiratory System , Urinary System
Respiratory  System , Urinary SystemRespiratory  System , Urinary System
Respiratory System , Urinary System
RushiMandali
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdfAllomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition OecdEnergy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
GeorgeDiamandis11
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptxCapitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 

Introduction to Java Scripting

  • 1. Introduction to Java Scripting by: Alexandra Vlachakis Sandy Creek High School, Fayette County Schools Content and Resources Used With Permission: W3 Schools. www.w3schools.com. 12-25-11.
  • 2. Lesson 1 : Introduction to Java Scripting
  • 3. What is JavaScript? JavaScript is the most popular scripting language on the internet, and works in all major browsers, such as Internet Explorer, Firefox, Chrome, Opera, and Safari. JavaScript was designed to add interactivity to HTML pages Before you start this lesson you should already know HTML
  • 4. What is JavaScript? JavaScript is a scripting language A scripting language is a lightweight programming language JavaScript is usually embedded directly into HTML pages JavaScript is an interpreted language (means that scripts execute without preliminary compilation) Everyone can use JavaScript without purchasing a license
  • 5. Are Java and JavaScript the same?   NO!   Java and JavaScript are two completely different languages in both concept and design! Java (developed by Sun Microsystems) is a powerful and much more complex programming language - in the same category as C and C++.
  • 6. What can a JavaScript do? HTML authors are normally not programmers JavaScript is a scripting language with a very simple syntax! It makes it possible for almost anyone to put small &quot;snippets&quot; of code into their HTML pages JavaScript can put dynamic text into an HTML page  
  • 7. What can a JavaScript do? For example you can write a JavaScript statement like this: document.write (&quot;<h1>&quot; + name + &quot;</h1>&quot;) This statement can write a variable text into an HTML page  
  • 8. Where can you put a JavaScript? JavaScripts in a page will be executed immediately while the page loads into the browser. This is not always what we want. Sometimes we want to execute a script when a page loads, other times when a user triggers an event.  
  • 9. Where can you put a JavaScript? Scripts can go in the <body> Scripts to be executed when the page loads go in the body section. If you place a script in the body section, it generates the content of a page. Scripts can also go in the in <head> Scripts to be executed when they are called, or when an event is triggered, go in the head section. If you place a script in the head section, you will ensure that the script is loaded before anyone uses it. Scripts can also be external   If you want to run the same JavaScript on several pages, without having to write the same script on every page, you can write a JavaScript in an external file. We will talk more about this later.
  • 10. Java Scripting Assignment 1 Type the following code into Notepad or Text Editor for Mac.   <html> <body> <script type=&quot;text/javascript&quot;> document.write(&quot; Hello World! &quot;); </script> </body> </html> Save your page as java1.html. When you preview it on the browser it should display: Hello World!
  • 11. Let's look at that code what does it mean? We will look at each line of code individually. For example line 1 - 2 are below. These you will remember at the beginning tags of HTML. Note your script starts after the <body> tag in this example. <html>  <body>   The next line tells the page the type of script you will be adding. In this case it is text. <script type=&quot; text /javascript&quot;>    
  • 12. More About The Code... Line 4 document.write(&quot; Hello World! &quot;); Tells the page to write the words &quot;Hello World&quot; on your webpage.   To write text in your JavaScript you need to put it in between quotes and in parenthesis The code also states it is a document.write command This the standard JavaScript command for writing output to a page. By entering the document.write command between the <script> and </script> tags, the browser will recognize it as a JavaScript command and execute the code line. As I mentioned for this example the browser will write Hello World!  on the page
  • 13. Closing Your Lines Of Code Line 5 is the ending tag of the script. </script> You need to just like in HTML close your <script> when you have completed your JavaScript. Why is it important to close the <script> tag? Line 6-7 close your HTML tags <body> <html>. </body> </html>
  • 14. Lesson 2 : What Can Java Scripting Do?
  • 15. What can Javascripting do? JavaScript can react to events - A JavaScript can be set to execute when something happens, like when a page has finished loading or when a user clicks on an HTML element JavaScript can read and write HTML elements A JavaScript can read and change the content of an HTML element   JavaScript can be used to validate data - A JavaScript can be used to validate form data before it is submitted to a server. This saves the server from extra processing
  • 16. What else can Java Scripting do? JavaScript can be used to detect the visitor's browser A JavaScript can be used to detect the visitor's browser - load another page specifically designed for that browser JavaScript can be used to create cookies - A JavaScript can be used to store and retrieve information on the visitor's computer
  • 17. Lesson 3 : Syntax & Rules for Java Scripting
  • 18. JavaScript is Case Sensitive Unlike HTML, JavaScript is case sensitive! Therefore watch your capitalization closely Especially when you write JavaScript for: statements create or call variables objects and functions  
  • 19. JavaScripting and Semicolons   It is normal to add a semicolon at the end of each executable statement.   ex. document.write(&quot;Hello Dolly&quot;); Most people think this is a good programming practice, and most often you will see this in JavaScript examples on the web.
  • 20. Java Scripting and Semicolons The semicolon is optional (according to the JavaScript standard), and the browser is supposed to interpret the end of the line as the end of the statement. Because of this you will often see examples without the semicolon at the end. Note: Using semicolons makes it possible to write multiple statements on one line. Where else did we use semicolons to write code?
  • 21. JavaScript Code JavaScript code (or just JavaScript) is a sequence of JavaScript statements. Each statement is executed by the browser in the sequence they are written. In the following example we will write a heading and two paragraphs to a web page.
  • 22. Java Scripting: Syntax & Rules Assignment 2 <script type=&quot;text/javascript&quot;> document.write (&quot;<h1>This is a heading</h1>&quot;); document.write (&quot;<p>This is a paragraph.</p>&quot;); document.write (&quot;<p>This is another paragraph.</p>&quot;);  </script> Save your page as java-syntax.html.
  • 23. Lesson 4 : Java Scripting Blocks
  • 24. JavaScript Blocks JavaScript statements can be grouped together in blocks. Blocks start with a left curly bracket { and ends with a right curly bracket } The purpose of a block is to make the sequence of statements execute together. The following example will write a heading and two paragraphs to a web page.
  • 25. Java Scripting: Blocks Assignment 3 <script type=&quot;text/javascript&quot;> { document.write (&quot;<h1>This is a heading</h1>&quot;); document.write (&quot;<p>This is a paragraph.</p>&quot;); document.write (&quot;<p>This is another paragraph.</p>&quot;); } </script> Save your file as Java-blocks.html The example above is not very useful. It just demonstrates the use of a block. Normally a block is used to group statements together in a function or in a condition (where a group of statements should be executed if a condition is met). You will learn more about functions and conditions in later chapters.
  • 26. Lesson 5 : Java Script Comments
  • 27. JavaScript Comments JavaScript comments can be used to make the code more readable. Comments can be added to explain the JavaScript, or to make the code more readable. Single line comments start with //.  
  • 28. Java Scripting: Comments Assignment 4 <script type=&quot;text/javascript&quot;> // Write a heading document.write (&quot;<h1>This is a heading</h1>&quot;); // Write two paragraphs document.write (&quot;<p>This is a paragraph.</p>&quot;); document.write (&quot;<p>This is another paragraph.</p>&quot;); </script> The following example uses single line comments to explain the code they will not show up when displayed in the browser: Save your file as Java-comments.html
  • 29. Lesson 6 : Java Scripting Variables
  • 30. Algebra Basics Do you remember algebra class? x=5, y=6, z=x+y Do you remember that a letter (like x) could be used to hold a value (like 5), and that you could use the information above to calculate the value of z to be 11? These letters are called variables, and variables can be used to hold values (x=5) or expressions (z=x+y).
  • 31. JavaScript Variables As with algebra, JavaScript variables are used to hold values or expressions. A variable can have a short name, like x, or a more descriptive name, like “ car name ”.
  • 32. Rules for JavaScript variable names: Variable names are case sensitive (y and Y are two different variables) Variable names must begin with a letter or the underscore character Note: Because JavaScript is case sensitive, variable names are case sensitive.
  • 33. Java Scripting: Variables Assignment 5 Type the following code into a new notepad document <html> <body> <script type=&quot;text/javascript&quot;> var firstname; firstname=&quot;Hege&quot;; document.write(firstname); document.write(&quot;<br />&quot;); firstname=&quot;Tove&quot;; document.write(firstname); </script> <p>The script above declares a variable, assigns a value to it, displays the value, changes the value, and displays the value again.</p> </body> </html> Save your file as Java-variables.html
  • 34. Lesson 7 : Java Scripting Conditional Statements
  • 35. Conditional Statements Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this.   In JavaScript we have the following conditional statements: if statement - 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...else if....else statement - use this statement to select one of many blocks of code to be executed switch statement - use this statement to select one of many blocks of code to be executed
  • 36. If statements Use the ‘ if ’ statement to execute some code only if a specified condition is true. Syntax if ( condition )   {   code to be executed if condition is true   } Note that ‘ if ’ is written in lowercase letters. Using uppercase letters ( IF ) will generate a JavaScript error!
  • 37. Type the following code: <script type=&quot;text/javascript&quot;> //Write a &quot;Good morning&quot; greeting if //the time is less than 10 var d=new Date(); var time=d.getHours(); if (time<10)   {   document.write(&quot;<b>Good morning</b>&quot;);   } </script>   Save your file as Java-if.html. Change the time and refresh your browser and see what happens. Java Scripting: If Statement Assignment 6 Note that there is no ‘else’ in this syntax. You tell the browser to execute some code only if the specified condition is true .
  • 38. If...else Statements Use the if....else statement to execute some code if a condition is true and another code if the condition is not true. Syntax if (condition)   {   code to be executed if condition is true   } else   {   code to be executed if condition is not true   }
  • 39. Type the following code: <script type=&quot;text/javascript&quot;> //write a &quot;Good morning&quot; greeting if //the time is less than 14 var d=new Date(); var time=d.getHours(); if (time<14) { document.write(&quot;<b>Good afternoon</b>&quot;); } else { document.write(&quot;<b>Good evening</b>&quot;); } Save your file as Java-if-else.html Change the time and refresh your browser and see what happens. Java Scripting: If Else Statement Assignment 7
  • 40. If...else if...else Statement Use the if....else if...else statement to select one of several blocks of code to be executed. 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   }
  • 41. Java Scripting: If Statement else Assignment 8 <script type=&quot;text/javascript&quot;> var d = new Date() var time = d.getHours() if (time<10)   {   document.write(&quot;<b>Good morning</b>&quot;);   } else if (time>10 && time<16)   {   document.write(&quot;<b>Good day</b>&quot;);   } else   {   document.write(&quot;<b>Hello World!</b>&quot;);   } </script> Save your file as , Java-if –else-else.html Change the time and refresh your browser and see what happens.
  • 42. Java Scripting: Switch Conditional Statements Assignment 9 <html> <body> <script type=&quot;text/javascript&quot;> var r=Math.random(); if (r>0.5) { document.write(&quot;<a href='http:// www.w3.org/ '>W3</a>&quot;); } else { document.write(&quot;<a href='http://www.sandycreekhighschool.com'>Sandy Creek High School</a>&quot;); } </script> </body> </html> *In this example you have a 50/50 chance of getting one or the other link. Save your file as Java-switch.html Change the time and refresh your browser and see what happens.
  • 43. Culminating Performance Task Make it Snow Web Page Students will create a page that allows it to snow (see example). Students can personalize the page by adding content, colors, and their own version of snow like leaves or footballs. Students can present the page to the class.