SlideShare a Scribd company logo
Introduction to Javascript
Module 1
What is JavaScript?
● JavaScript was initially created to “make web pages alive”.
● The programs in this language are called scripts. They can be written right in a web
page’s HTML and run automatically as the page loads.
● Scripts are provided and executed as plain text. They don’t need special preparation or
compilation to run.
● In this aspect, JavaScript is very different from another language called Java.
● JavaScript can execute not only in the browser, on any device that has a special
program called the JavaScript engine.
Java Script (Module 1).pptx
Why Js
● client-side scripting (JavaScript) benefits:
● usability: can modify a page without having to post back to the
server (faster UI)
● efficiency: can make small, quick changes to page without waiting
for server
● event-driven: can respond to user actions like clicks and key
presses
Java Script (Module 1).pptx
Where to write js code ?
● script tag should be placed in HTML page's head
● script code is stored in a separate .js file
● JS code can be placed directly in the HTML file's body or head (like CSS)
but this is bad style (should separate content, presentation, and behavior)
<script src="filename" type="text/javascript"> script(s) </script>
HTML
Comments (same as Java)
// single-line comment
/* multi-line comment */
JS
identical to Java's comment syntax
4 comment syntaxes
HTML: <!-- comment -->
CSS/JS/PHP: /* comment */
Java/JS/PHP: // comment
PHP: # comment
Script 1:
Use of alert box
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JavaScript 1</title>
<script>
alert('Hello, I am ____!');
</script>
</head>
<body>
</body>
</html>
Using document.write() - This simply prints the specified text or HTML content
to the page.
<!DOCTYPE html>
<html>
<body>
<h1>My First Web Page</h1>
<p>My first paragraph.</p>
<script>
document.write(5 + 6);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h1>My First Web Page</h1>
<p>My first paragraph.</p>
<script>
document.write("<b>I am new text</b>");
</script>
</body>
</html>
String in webpage HTML tag in webpage
Using document.writeln() -method is identical to the write() method, with
the addition of writing a newline character after each statement.
<!DOCTYPE html>
<html>
<body>
<script>
document.write(5 + 6);
document.write(“<b> my lucky
number</b>”);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<script>
document.writeln(5 + 6);
document.writeln(“<b> my lucky
number</b>”);
</script>
</body>
</html>
document.write document.writeln
4 Ways to Declare
a JavaScript
Variable:
var keyword
var x = 5;
var y = 6;
var z = x + y;
let keyword
let x = 5;
let y = 6;
let z = x + y;
undeclared variables
x = 5;
y = 6;
z = x + y;
Scope of var and let
<!DOCTYPE html>
<html>
<body>
<h2>Redeclaring a Variable Using let</h2>
<script>
let x = 10;
document.writeln(x); {
let x = 2;
document.writeln(x); }
document.writeln(x);
</script> </body> </html>
var x = 10;
// Here x is 10
{
var x = 2;
// Here x is 2
}
// Here x is 2
let var
Declare a variable with
const unless you know that
the value will change.
const num1 = 5;
const num2 = 3;
// add two numbers
const sum = num1 + num2;
// display the sum
document.write('The sum of ' + num1 + ' and ' + num2
+ ' is: ' + sum);
JavaScript Popup Boxes
JavaScript has three kind of popup boxes: Alert box, Confirm box, and Prompt box.
An alert box is often used if you
want to make sure information
comes through to the user.
When an alert box pops up, the
user will have to click "OK" to
proceed.
<!DOCTYPE html>
<html>
<body> <h2>Alert Example</h2>
<button onclick="displayBox()">Magic</button>
<script>
function displayBox() {
alert("I am an alert box!n Nice to meet you"); }
</script>
</body>
</html>
A confirm box is often used
if you want the user to verify
or accept something.
When a confirm box pops
up, the user will have to click
either "OK" or "Cancel" to
proceed.
If the user clicks "OK", the
box returns true. If the user
clicks "Cancel", the box
returns false.
<!DOCTYPE html>
<html>
<body>
<h2>Confirm Box</h2>
<button onclick="typeReply()">Check</button>
<p id="display"></p> <script>
function typeReply() {
var txt;
if (confirm("Would you like to order tea?")) {
txt = "Tea is ordered";
} else {
txt = "You pressed Cancel!";
}
document.getElementById("display").innerHTML = txt;
}
</script>
</body>
</html>
A prompt box is often used if
you want the user to input a
value before entering a page.
When a prompt box pops up,
the user will have to click
either "OK" or "Cancel" to
proceed after entering an
input value.
If the user clicks "OK" the
box returns the input value.
If the user clicks "Cancel" the
box returns null.
<!DOCTYPE html>
<html>
<body>
<h2>Prompt</h2>
<button onclick="userName()">Try it</button>
<p id="demo"></p>
<script>
function userName() {
let text;
let person = prompt("Please enter your name:", "Richie");
if (person == null || person == "") {
text = "Empty";
} else {
text = "Hello " + person + "! How are you today?";
}
document.getElementById("demo").innerHTML = text;
}
</script></body></html>
References
https://javascript.info/intro#what-is-javascript

More Related Content

Similar to Java Script (Module 1).pptx (20)

Java Script
Java ScriptJava Script
Java Script
Dr. SURBHI SAROHA
 
JavaScript Training
JavaScript TrainingJavaScript Training
JavaScript Training
Ramindu Deshapriya
 
Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>
Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>
Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>
tutorialsruby
 
Essential_Javascript_--_A_Javascript_Tutorial
Essential_Javascript_--_A_Javascript_TutorialEssential_Javascript_--_A_Javascript_Tutorial
Essential_Javascript_--_A_Javascript_Tutorial
tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
tutorialsruby
 
Essential_Javascript_--_A_Javascript_Tutorial
Essential_Javascript_--_A_Javascript_TutorialEssential_Javascript_--_A_Javascript_Tutorial
Essential_Javascript_--_A_Javascript_Tutorial
tutorialsruby
 
Javascript alert and confrim box
Javascript alert and confrim boxJavascript alert and confrim box
Javascript alert and confrim box
Jesus Obenita Jr.
 
Javascript
JavascriptJavascript
Javascript
Manav Prasad
 
lect4
lect4lect4
lect4
tutorialsruby
 
lect4
lect4lect4
lect4
tutorialsruby
 
JavaScript with Syntax & Implementation
JavaScript with Syntax & ImplementationJavaScript with Syntax & Implementation
JavaScript with Syntax & Implementation
Soumen Santra
 
Upstate CSCI 450 WebDev Chapter 4
Upstate CSCI 450 WebDev Chapter 4Upstate CSCI 450 WebDev Chapter 4
Upstate CSCI 450 WebDev Chapter 4
DanWooster1
 
Unit5_Web_Updvvgxsvjbffcvvgbjifszated.pptx
Unit5_Web_Updvvgxsvjbffcvvgbjifszated.pptxUnit5_Web_Updvvgxsvjbffcvvgbjifszated.pptx
Unit5_Web_Updvvgxsvjbffcvvgbjifszated.pptx
1si23bt001
 
Upstate CSCI 450 WebDev Chapter 4
Upstate CSCI 450 WebDev Chapter 4Upstate CSCI 450 WebDev Chapter 4
Upstate CSCI 450 WebDev Chapter 4
DanWooster1
 
JAVA SCRIPT
JAVA SCRIPTJAVA SCRIPT
JAVA SCRIPT
Mohammed Hussein
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java script
nanjil1984
 
wp-UNIT_III.pptx
wp-UNIT_III.pptxwp-UNIT_III.pptx
wp-UNIT_III.pptx
GANDHAMKUMAR2
 
Lecture6
Lecture6Lecture6
Lecture6
Sazilah Salam
 
Basics
BasicsBasics
Basics
Max Friel
 
Wt unit 5
Wt unit 5Wt unit 5
Wt unit 5
team11vgnt
 
Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>
Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>
Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>
tutorialsruby
 
Essential_Javascript_--_A_Javascript_Tutorial
Essential_Javascript_--_A_Javascript_TutorialEssential_Javascript_--_A_Javascript_Tutorial
Essential_Javascript_--_A_Javascript_Tutorial
tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
tutorialsruby
 
Essential_Javascript_--_A_Javascript_Tutorial
Essential_Javascript_--_A_Javascript_TutorialEssential_Javascript_--_A_Javascript_Tutorial
Essential_Javascript_--_A_Javascript_Tutorial
tutorialsruby
 
Javascript alert and confrim box
Javascript alert and confrim boxJavascript alert and confrim box
Javascript alert and confrim box
Jesus Obenita Jr.
 
JavaScript with Syntax & Implementation
JavaScript with Syntax & ImplementationJavaScript with Syntax & Implementation
JavaScript with Syntax & Implementation
Soumen Santra
 
Upstate CSCI 450 WebDev Chapter 4
Upstate CSCI 450 WebDev Chapter 4Upstate CSCI 450 WebDev Chapter 4
Upstate CSCI 450 WebDev Chapter 4
DanWooster1
 
Unit5_Web_Updvvgxsvjbffcvvgbjifszated.pptx
Unit5_Web_Updvvgxsvjbffcvvgbjifszated.pptxUnit5_Web_Updvvgxsvjbffcvvgbjifszated.pptx
Unit5_Web_Updvvgxsvjbffcvvgbjifszated.pptx
1si23bt001
 
Upstate CSCI 450 WebDev Chapter 4
Upstate CSCI 450 WebDev Chapter 4Upstate CSCI 450 WebDev Chapter 4
Upstate CSCI 450 WebDev Chapter 4
DanWooster1
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java script
nanjil1984
 

More from Shehrevar Davierwala (20)

Introduction_Swift
Introduction_SwiftIntroduction_Swift
Introduction_Swift
Shehrevar Davierwala
 
PsudoCode.pptx
PsudoCode.pptxPsudoCode.pptx
PsudoCode.pptx
Shehrevar Davierwala
 
Number System.pptx
Number System.pptxNumber System.pptx
Number System.pptx
Shehrevar Davierwala
 
Website in Clicks Day 2
Website in Clicks Day 2Website in Clicks Day 2
Website in Clicks Day 2
Shehrevar Davierwala
 
Develop Website in Clicks
Develop Website in ClicksDevelop Website in Clicks
Develop Website in Clicks
Shehrevar Davierwala
 
Build Virtual Assistant Using AI
Build Virtual Assistant Using AI Build Virtual Assistant Using AI
Build Virtual Assistant Using AI
Shehrevar Davierwala
 
Build brand reputation using facebook
Build brand reputation using facebookBuild brand reputation using facebook
Build brand reputation using facebook
Shehrevar Davierwala
 
Digital Marketing Session 2
Digital Marketing Session 2Digital Marketing Session 2
Digital Marketing Session 2
Shehrevar Davierwala
 
Learn Digital Marketing : 0 to Hero Day 1
Learn Digital Marketing :  0 to Hero Day 1 Learn Digital Marketing :  0 to Hero Day 1
Learn Digital Marketing : 0 to Hero Day 1
Shehrevar Davierwala
 
Standard template
Standard templateStandard template
Standard template
Shehrevar Davierwala
 
Digital Marketing for Sustainable Business - Afghan Perspective
Digital Marketing for Sustainable Business - Afghan Perspective  Digital Marketing for Sustainable Business - Afghan Perspective
Digital Marketing for Sustainable Business - Afghan Perspective
Shehrevar Davierwala
 
Developing stunning website in clicks - 2
Developing stunning website in clicks - 2Developing stunning website in clicks - 2
Developing stunning website in clicks - 2
Shehrevar Davierwala
 
Developing stunning website in clicks
Developing stunning website in clicksDeveloping stunning website in clicks
Developing stunning website in clicks
Shehrevar Davierwala
 
Google forms for data analysis
Google forms for data analysisGoogle forms for data analysis
Google forms for data analysis
Shehrevar Davierwala
 
Webdesign session1
Webdesign session1Webdesign session1
Webdesign session1
Shehrevar Davierwala
 
Tech talk webtech
Tech talk webtechTech talk webtech
Tech talk webtech
Shehrevar Davierwala
 
Tech talk php_cms
Tech talk php_cmsTech talk php_cms
Tech talk php_cms
Shehrevar Davierwala
 
Ph pbasics
Ph pbasicsPh pbasics
Ph pbasics
Shehrevar Davierwala
 
Php mysql
Php mysqlPhp mysql
Php mysql
Shehrevar Davierwala
 
Java operators
Java operatorsJava operators
Java operators
Shehrevar Davierwala
 
Ad

Recently uploaded (20)

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
 
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
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptxIDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
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
 
Strengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptxStrengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptx
SteffMusniQuiballo
 
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
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
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
 
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
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti MpdBasic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
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
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big CycleRay Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
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
 
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
 
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
 
Respiratory System , Urinary System
Respiratory  System , Urinary SystemRespiratory  System , Urinary System
Respiratory System , Urinary System
RushiMandali
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptxIDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
Strengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptxStrengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptx
SteffMusniQuiballo
 
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
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
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
 
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
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti MpdBasic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
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
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big CycleRay Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
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
 
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
 
Ad

Java Script (Module 1).pptx

  • 2. What is JavaScript? ● JavaScript was initially created to “make web pages alive”. ● The programs in this language are called scripts. They can be written right in a web page’s HTML and run automatically as the page loads. ● Scripts are provided and executed as plain text. They don’t need special preparation or compilation to run. ● In this aspect, JavaScript is very different from another language called Java. ● JavaScript can execute not only in the browser, on any device that has a special program called the JavaScript engine.
  • 4. Why Js ● client-side scripting (JavaScript) benefits: ● usability: can modify a page without having to post back to the server (faster UI) ● efficiency: can make small, quick changes to page without waiting for server ● event-driven: can respond to user actions like clicks and key presses
  • 6. Where to write js code ? ● script tag should be placed in HTML page's head ● script code is stored in a separate .js file ● JS code can be placed directly in the HTML file's body or head (like CSS) but this is bad style (should separate content, presentation, and behavior) <script src="filename" type="text/javascript"> script(s) </script> HTML
  • 7. Comments (same as Java) // single-line comment /* multi-line comment */ JS identical to Java's comment syntax 4 comment syntaxes HTML: <!-- comment --> CSS/JS/PHP: /* comment */ Java/JS/PHP: // comment PHP: # comment
  • 8. Script 1: Use of alert box <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>JavaScript 1</title> <script> alert('Hello, I am ____!'); </script> </head> <body> </body> </html>
  • 9. Using document.write() - This simply prints the specified text or HTML content to the page. <!DOCTYPE html> <html> <body> <h1>My First Web Page</h1> <p>My first paragraph.</p> <script> document.write(5 + 6); </script> </body> </html> <!DOCTYPE html> <html> <body> <h1>My First Web Page</h1> <p>My first paragraph.</p> <script> document.write("<b>I am new text</b>"); </script> </body> </html> String in webpage HTML tag in webpage
  • 10. Using document.writeln() -method is identical to the write() method, with the addition of writing a newline character after each statement. <!DOCTYPE html> <html> <body> <script> document.write(5 + 6); document.write(“<b> my lucky number</b>”); </script> </body> </html> <!DOCTYPE html> <html> <body> <script> document.writeln(5 + 6); document.writeln(“<b> my lucky number</b>”); </script> </body> </html> document.write document.writeln
  • 11. 4 Ways to Declare a JavaScript Variable: var keyword var x = 5; var y = 6; var z = x + y; let keyword let x = 5; let y = 6; let z = x + y; undeclared variables x = 5; y = 6; z = x + y;
  • 12. Scope of var and let <!DOCTYPE html> <html> <body> <h2>Redeclaring a Variable Using let</h2> <script> let x = 10; document.writeln(x); { let x = 2; document.writeln(x); } document.writeln(x); </script> </body> </html> var x = 10; // Here x is 10 { var x = 2; // Here x is 2 } // Here x is 2 let var
  • 13. Declare a variable with const unless you know that the value will change. const num1 = 5; const num2 = 3; // add two numbers const sum = num1 + num2; // display the sum document.write('The sum of ' + num1 + ' and ' + num2 + ' is: ' + sum);
  • 14. JavaScript Popup Boxes JavaScript has three kind of popup boxes: Alert box, Confirm box, and Prompt box. An alert box is often used if you want to make sure information comes through to the user. When an alert box pops up, the user will have to click "OK" to proceed. <!DOCTYPE html> <html> <body> <h2>Alert Example</h2> <button onclick="displayBox()">Magic</button> <script> function displayBox() { alert("I am an alert box!n Nice to meet you"); } </script> </body> </html>
  • 15. A confirm box is often used if you want the user to verify or accept something. When a confirm box pops up, the user will have to click either "OK" or "Cancel" to proceed. If the user clicks "OK", the box returns true. If the user clicks "Cancel", the box returns false. <!DOCTYPE html> <html> <body> <h2>Confirm Box</h2> <button onclick="typeReply()">Check</button> <p id="display"></p> <script> function typeReply() { var txt; if (confirm("Would you like to order tea?")) { txt = "Tea is ordered"; } else { txt = "You pressed Cancel!"; } document.getElementById("display").innerHTML = txt; } </script> </body> </html>
  • 16. A prompt box is often used if you want the user to input a value before entering a page. When a prompt box pops up, the user will have to click either "OK" or "Cancel" to proceed after entering an input value. If the user clicks "OK" the box returns the input value. If the user clicks "Cancel" the box returns null. <!DOCTYPE html> <html> <body> <h2>Prompt</h2> <button onclick="userName()">Try it</button> <p id="demo"></p> <script> function userName() { let text; let person = prompt("Please enter your name:", "Richie"); if (person == null || person == "") { text = "Empty"; } else { text = "Hello " + person + "! How are you today?"; } document.getElementById("demo").innerHTML = text; } </script></body></html>