SlideShare a Scribd company logo
JS
What am I learning?
This is JavaScript (JS), a programming language. There are many languages,
but JS has many uses and is easy to learn.
What can we use JavaScript for?
● make websites respond to user interaction
● build apps and games (e.g. blackjack)
● access information on the Internet (e.g. find out the top trending words
on Twitter by topic)
● organize and present data (e.g. automate spreadsheet work; data
visualization)
Example:Confirm box
<html>
<head>
<script>
confirm('This is an example of using JS to create some interaction on a website. Click OK to continue!');
</script>
</head>
<body></body>
</html>
Interactive JavaScript
● What is programming?
○ Programming is like writing a list of instructions to the computer so it can do cool stuff
with your information.
○ To do any of these actions, the program needs an input. You can ask for input with a
prompt.
○ Examples:
■ prompt("What is your name?");
■ prompt("What is Ubuntu?");
Next task
Modify the above program by asking student name using prompt box
<html>
<head>
<script>
confirm('This is an example of using JS to create some interaction on a website. Click OK to continue!');
prompt(“what is your name?”);
</script></head>
<body></body>
</html>
Data Types , Numbers & Strings
Data comes in various types. You have used two already!
1. Numbers are quantities, just like you're used to. You can do math with
them.
2. strings are sequences of characters, like the letters a-z, spaces, and even
numbers. These are all strings: "Ryan", "4" and "What is your name?"
Strings are extremely useful as labels, names, and content for your
programs.
● To make a number in your code, just write a number as numerals
without quotes: 42, 190.12334.
● To write a string, surround words with quotes: "What is your name?"
Task
● Write a string with at least 3 words. Check out the examples of strings
above
Eg: document.write(“something”);
Try to yourself ...
What will be the output???
Datatype:Boolean
Nice job! Next let's look at booleans. A boolean is either true or false.
For example, comparing two numbers returns a true or false result:
23 > 10 is true
5 < 4 is false
Task..
Let's compare two numbers 10&20 to return a true result:
Using console.log
You may have noticed that the interpreter doesn't print out every single thing
it does. So if we want to know what it's thinking, we sometimes have to ask it
to speak to us.
console.log() will take whatever is inside the parentheses and log it to the
console below your code—that's why it's called console.log()!
This is commonly called printing out.
● console.log(2 * 5)
● console.log("Hello")
Try it yourself..
1. <html>
2. <head><script>
3. confirm('This is an example of using JS to create some interaction on a website. Click OK to
continue!');
4. console.log(10*10);
5. console.log("Lets start...");
6. </script></head>
7. <body></body>
8. </html>
Comparisons
So far we've learned about three data types:
● strings (e.g. "dogs go woof!")
● numbers (e.g. 4, 10)
● booleans (e.g. false, 5 > 4)
Now let's learn more about comparison operators.
List of comparison operators:
> Greater than
< Less than
<= Less than or equal to
>= Greater than or equal to
=== Equal to
!== Not equal to
Try to use each of the operators above
● console.log(15 4); // 15 > 4 evaluates to true, so true is
printed.
// Fill in with >, <, === so that the following print out true:
● console.log("Xiao Hui".length 122);
● console.log("Goody Donaldson".length 8);
● console.log(8*2 16);
Choose the correct comparison operator
to make each of the four statements print
out true.
List of comparison operators:
> Greater than
< Less than
<= Less than or equal to
>= Greater than or equal to
=== Equal to
!== Not equal to
Try to use each of the operators above
● console.log(15 > 4); // 15 > 4 evaluates to true, so true is
printed.
// Fill in with >, <, === so that the following print out true:
● console.log("Xiao Hui".length < 122);
● console.log("Goody Donaldson".length > 8);
● console.log(8*2 === 16);
Choose the correct comparison operator
to make each of the four statements print
out true.
Variables
We have learned how to do a few things now: make strings,numbers, do
basic math. Not bad for a day's work!
To do more complex coding, we need a way to 'save' the values from our
coding. We do this by defining a variable with a specific, case-sensitive name.
Once you create (or declare) a variable as having a particular name, you can
then call up that value by typing the variable name.
Syntax:
var varName = data;
Variables..
Example:
● var myName = "Leng";
● var isOdd = true;
Task
● Create a variable called myAge and type in your age.
Task
Follow the instructions in the comments in the code to continue.
1. // Declare a variable on line 3 called
2. // myCountry and give it a string value.
3. // Use console.log to print out the length of the variable myCountry.
4. // Use console.log to print out the first three letters of myCountry.
Task
Follow the instructions in the comments in the code to continue.
1. // Declare a variable on line 3 called
2. // myCountry and give it a string value.
3. var myCountry="india"
4. // Use console.log to print out the length of the variable myCountry.
5. console.log(myCountry.length);
6. // Use console.log to print out the first three letters of myCountry.
7. console.log(myCountry.substring(0,3));
Change variable values
So far, we've seen
● how to create a variable
● how to use a variable
Let's now see how to change a variable's value. A variable's value is easily
changed. Just pretend you are creating a new variable while using the same
name of the existing variable!
Example:
var myAge = "Thirty";
myAge = "Thirty-one";
Now the value of myAge is "Thirty-one"!
typeof()
You can use the JavaScript typeof operator to find the type of a JavaScript
variable.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <script>
5. var x ="Cybersquare"+ 2017;
6. var myvar=5;
7. var bool =true;
8. alert(typeof myvar); //alerts "number"
9. alert(typeof x)
10. </script>
11. </head>
12. <body>
13. <p>You can use the JavaScript typeof operator to find the type of a JavaScript variable.</p>
14. </body>
15. </html>
Conclusion
Let's do a quick review!
● Datatypes
● Variables
● Manipulating numbers & strings
● Manipulating numbers & strings

More Related Content

Similar to Js tutorial(Basic concepts, running a program ,console,variable,types etc..) (20)

Javascript 101
Javascript 101Javascript 101
Javascript 101
Shlomi Komemi
 
Lecture17 ie321 dr_atifshahzad_js
Lecture17 ie321 dr_atifshahzad_jsLecture17 ie321 dr_atifshahzad_js
Lecture17 ie321 dr_atifshahzad_js
Atif Shahzad
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
Varun C M
 
Unit - 4 all script are here Javascript.pptx
Unit - 4 all script are here Javascript.pptxUnit - 4 all script are here Javascript.pptx
Unit - 4 all script are here Javascript.pptx
kushwahanitesh592
 
Introduction to javascript.ppt
Introduction to javascript.pptIntroduction to javascript.ppt
Introduction to javascript.ppt
BArulmozhi
 
Intro to javascript (5:2)
Intro to javascript (5:2)Intro to javascript (5:2)
Intro to javascript (5:2)
Thinkful
 
javascript-variablesanddatatypes-130218094831-phpapp01.pdf
javascript-variablesanddatatypes-130218094831-phpapp01.pdfjavascript-variablesanddatatypes-130218094831-phpapp01.pdf
javascript-variablesanddatatypes-130218094831-phpapp01.pdf
AlexShon3
 
13665449.ppt
13665449.ppt13665449.ppt
13665449.ppt
JP Chicano
 
Javascript essentials
Javascript essentialsJavascript essentials
Javascript essentials
Bedis ElAchèche
 
03. Week 03.pptx
03. Week 03.pptx03. Week 03.pptx
03. Week 03.pptx
Vinc2ntCabrera
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
Julie Iskander
 
Java Script Basic to Advanced For Beginner to Advanced Learner.pptx
Java Script Basic to Advanced For Beginner to Advanced Learner.pptxJava Script Basic to Advanced For Beginner to Advanced Learner.pptx
Java Script Basic to Advanced For Beginner to Advanced Learner.pptx
sanjaydhumal26
 
JavaScript 1 for high school
JavaScript 1 for high schoolJavaScript 1 for high school
JavaScript 1 for high school
jekkilekki
 
Learn java script
Learn java scriptLearn java script
Learn java script
Mahmoud Asadi
 
An introduction to javascript
An introduction to javascriptAn introduction to javascript
An introduction to javascript
tonyh1
 
JavaScript 101
JavaScript 101JavaScript 101
JavaScript 101
Mindy McAdams
 
data-types-operators-datatypes-operators.ppt
data-types-operators-datatypes-operators.pptdata-types-operators-datatypes-operators.ppt
data-types-operators-datatypes-operators.ppt
Gagan Rana
 
FYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III JavascriptFYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III Javascript
Arti Parab Academics
 
Java script ppt from students in internet technology
Java script ppt from students in internet technologyJava script ppt from students in internet technology
Java script ppt from students in internet technology
SherinRappai
 
CSC PPT 13.pptx
CSC PPT 13.pptxCSC PPT 13.pptx
CSC PPT 13.pptx
DrRavneetSingh
 
Lecture17 ie321 dr_atifshahzad_js
Lecture17 ie321 dr_atifshahzad_jsLecture17 ie321 dr_atifshahzad_js
Lecture17 ie321 dr_atifshahzad_js
Atif Shahzad
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
Varun C M
 
Unit - 4 all script are here Javascript.pptx
Unit - 4 all script are here Javascript.pptxUnit - 4 all script are here Javascript.pptx
Unit - 4 all script are here Javascript.pptx
kushwahanitesh592
 
Introduction to javascript.ppt
Introduction to javascript.pptIntroduction to javascript.ppt
Introduction to javascript.ppt
BArulmozhi
 
Intro to javascript (5:2)
Intro to javascript (5:2)Intro to javascript (5:2)
Intro to javascript (5:2)
Thinkful
 
javascript-variablesanddatatypes-130218094831-phpapp01.pdf
javascript-variablesanddatatypes-130218094831-phpapp01.pdfjavascript-variablesanddatatypes-130218094831-phpapp01.pdf
javascript-variablesanddatatypes-130218094831-phpapp01.pdf
AlexShon3
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
Julie Iskander
 
Java Script Basic to Advanced For Beginner to Advanced Learner.pptx
Java Script Basic to Advanced For Beginner to Advanced Learner.pptxJava Script Basic to Advanced For Beginner to Advanced Learner.pptx
Java Script Basic to Advanced For Beginner to Advanced Learner.pptx
sanjaydhumal26
 
JavaScript 1 for high school
JavaScript 1 for high schoolJavaScript 1 for high school
JavaScript 1 for high school
jekkilekki
 
An introduction to javascript
An introduction to javascriptAn introduction to javascript
An introduction to javascript
tonyh1
 
data-types-operators-datatypes-operators.ppt
data-types-operators-datatypes-operators.pptdata-types-operators-datatypes-operators.ppt
data-types-operators-datatypes-operators.ppt
Gagan Rana
 
FYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III JavascriptFYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III Javascript
Arti Parab Academics
 
Java script ppt from students in internet technology
Java script ppt from students in internet technologyJava script ppt from students in internet technology
Java script ppt from students in internet technology
SherinRappai
 

More from reshmy12 (6)

class diagrams and their relationships
class diagrams and   their relationshipsclass diagrams and   their relationships
class diagrams and their relationships
reshmy12
 
SUBMERGED FLOATING TUNNEL,COMPETITIVE FEATURES OF SFT CASE STUDY ON A SFT : T...
SUBMERGED FLOATING TUNNEL,COMPETITIVE FEATURES OF SFT CASE STUDY ON A SFT : T...SUBMERGED FLOATING TUNNEL,COMPETITIVE FEATURES OF SFT CASE STUDY ON A SFT : T...
SUBMERGED FLOATING TUNNEL,COMPETITIVE FEATURES OF SFT CASE STUDY ON A SFT : T...
reshmy12
 
Functions in c
Functions in cFunctions in c
Functions in c
reshmy12
 
Encryption.ppt
Encryption.pptEncryption.ppt
Encryption.ppt
reshmy12
 
Css with example
Css with exampleCss with example
Css with example
reshmy12
 
INTRUDUCTION TO HTML 5
INTRUDUCTION TO HTML 5INTRUDUCTION TO HTML 5
INTRUDUCTION TO HTML 5
reshmy12
 
class diagrams and their relationships
class diagrams and   their relationshipsclass diagrams and   their relationships
class diagrams and their relationships
reshmy12
 
SUBMERGED FLOATING TUNNEL,COMPETITIVE FEATURES OF SFT CASE STUDY ON A SFT : T...
SUBMERGED FLOATING TUNNEL,COMPETITIVE FEATURES OF SFT CASE STUDY ON A SFT : T...SUBMERGED FLOATING TUNNEL,COMPETITIVE FEATURES OF SFT CASE STUDY ON A SFT : T...
SUBMERGED FLOATING TUNNEL,COMPETITIVE FEATURES OF SFT CASE STUDY ON A SFT : T...
reshmy12
 
Functions in c
Functions in cFunctions in c
Functions in c
reshmy12
 
Encryption.ppt
Encryption.pptEncryption.ppt
Encryption.ppt
reshmy12
 
Css with example
Css with exampleCss with example
Css with example
reshmy12
 
INTRUDUCTION TO HTML 5
INTRUDUCTION TO HTML 5INTRUDUCTION TO HTML 5
INTRUDUCTION TO HTML 5
reshmy12
 
Ad

Recently uploaded (20)

Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Natan Silnitsky
 
Top 5 Task Management Software to Boost Productivity in 2025
Top 5 Task Management Software to Boost Productivity in 2025Top 5 Task Management Software to Boost Productivity in 2025
Top 5 Task Management Software to Boost Productivity in 2025
Orangescrum
 
Generative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its ApplicationsGenerative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its Applications
SandeepKS52
 
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
WSO2
 
OpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native BarcelonaOpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native Barcelona
Imma Valls Bernaus
 
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlowDevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
Aarno Aukia
 
Leveraging Foundation Models to Infer Intents
Leveraging Foundation Models to Infer IntentsLeveraging Foundation Models to Infer Intents
Leveraging Foundation Models to Infer Intents
Keheliya Gallaba
 
Migrating to Azure Cosmos DB the Right Way
Migrating to Azure Cosmos DB the Right WayMigrating to Azure Cosmos DB the Right Way
Migrating to Azure Cosmos DB the Right Way
Alexander (Alex) Komyagin
 
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdfThe Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
Varsha Nayak
 
How Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines OperationsHow Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines Operations
Insurance Tech Services
 
Best Inbound Call Tracking Software for Small Businesses
Best Inbound Call Tracking Software for Small BusinessesBest Inbound Call Tracking Software for Small Businesses
Best Inbound Call Tracking Software for Small Businesses
TheTelephony
 
Artificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across IndustriesArtificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across Industries
SandeepKS52
 
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptxIMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
usmanch7829
 
Software Testing & it’s types (DevOps)
Software  Testing & it’s  types (DevOps)Software  Testing & it’s  types (DevOps)
Software Testing & it’s types (DevOps)
S Pranav (Deepu)
 
Who will create the languages of the future?
Who will create the languages of the future?Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025
Safe Software
 
Agile Software Engineering Methodologies
Agile Software Engineering MethodologiesAgile Software Engineering Methodologies
Agile Software Engineering Methodologies
Gaurav Sharma
 
COBOL Programming with VSCode - IBM Certificate
COBOL Programming with VSCode - IBM CertificateCOBOL Programming with VSCode - IBM Certificate
COBOL Programming with VSCode - IBM Certificate
VICTOR MAESTRE RAMIREZ
 
Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)
VICTOR MAESTRE RAMIREZ
 
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Alluxio, Inc.
 
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Natan Silnitsky
 
Top 5 Task Management Software to Boost Productivity in 2025
Top 5 Task Management Software to Boost Productivity in 2025Top 5 Task Management Software to Boost Productivity in 2025
Top 5 Task Management Software to Boost Productivity in 2025
Orangescrum
 
Generative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its ApplicationsGenerative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its Applications
SandeepKS52
 
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
WSO2
 
OpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native BarcelonaOpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native Barcelona
Imma Valls Bernaus
 
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlowDevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
Aarno Aukia
 
Leveraging Foundation Models to Infer Intents
Leveraging Foundation Models to Infer IntentsLeveraging Foundation Models to Infer Intents
Leveraging Foundation Models to Infer Intents
Keheliya Gallaba
 
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdfThe Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
Varsha Nayak
 
How Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines OperationsHow Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines Operations
Insurance Tech Services
 
Best Inbound Call Tracking Software for Small Businesses
Best Inbound Call Tracking Software for Small BusinessesBest Inbound Call Tracking Software for Small Businesses
Best Inbound Call Tracking Software for Small Businesses
TheTelephony
 
Artificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across IndustriesArtificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across Industries
SandeepKS52
 
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptxIMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
usmanch7829
 
Software Testing & it’s types (DevOps)
Software  Testing & it’s  types (DevOps)Software  Testing & it’s  types (DevOps)
Software Testing & it’s types (DevOps)
S Pranav (Deepu)
 
Who will create the languages of the future?
Who will create the languages of the future?Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025
Safe Software
 
Agile Software Engineering Methodologies
Agile Software Engineering MethodologiesAgile Software Engineering Methodologies
Agile Software Engineering Methodologies
Gaurav Sharma
 
COBOL Programming with VSCode - IBM Certificate
COBOL Programming with VSCode - IBM CertificateCOBOL Programming with VSCode - IBM Certificate
COBOL Programming with VSCode - IBM Certificate
VICTOR MAESTRE RAMIREZ
 
Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)
VICTOR MAESTRE RAMIREZ
 
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Alluxio, Inc.
 
Ad

Js tutorial(Basic concepts, running a program ,console,variable,types etc..)

  • 1. JS
  • 2. What am I learning? This is JavaScript (JS), a programming language. There are many languages, but JS has many uses and is easy to learn. What can we use JavaScript for? ● make websites respond to user interaction ● build apps and games (e.g. blackjack) ● access information on the Internet (e.g. find out the top trending words on Twitter by topic) ● organize and present data (e.g. automate spreadsheet work; data visualization)
  • 3. Example:Confirm box <html> <head> <script> confirm('This is an example of using JS to create some interaction on a website. Click OK to continue!'); </script> </head> <body></body> </html>
  • 4. Interactive JavaScript ● What is programming? ○ Programming is like writing a list of instructions to the computer so it can do cool stuff with your information. ○ To do any of these actions, the program needs an input. You can ask for input with a prompt. ○ Examples: ■ prompt("What is your name?"); ■ prompt("What is Ubuntu?");
  • 5. Next task Modify the above program by asking student name using prompt box <html> <head> <script> confirm('This is an example of using JS to create some interaction on a website. Click OK to continue!'); prompt(“what is your name?”); </script></head> <body></body> </html>
  • 6. Data Types , Numbers & Strings Data comes in various types. You have used two already! 1. Numbers are quantities, just like you're used to. You can do math with them. 2. strings are sequences of characters, like the letters a-z, spaces, and even numbers. These are all strings: "Ryan", "4" and "What is your name?" Strings are extremely useful as labels, names, and content for your programs. ● To make a number in your code, just write a number as numerals without quotes: 42, 190.12334. ● To write a string, surround words with quotes: "What is your name?"
  • 7. Task ● Write a string with at least 3 words. Check out the examples of strings above Eg: document.write(“something”);
  • 8. Try to yourself ... What will be the output???
  • 9. Datatype:Boolean Nice job! Next let's look at booleans. A boolean is either true or false. For example, comparing two numbers returns a true or false result: 23 > 10 is true 5 < 4 is false
  • 10. Task.. Let's compare two numbers 10&20 to return a true result:
  • 11. Using console.log You may have noticed that the interpreter doesn't print out every single thing it does. So if we want to know what it's thinking, we sometimes have to ask it to speak to us. console.log() will take whatever is inside the parentheses and log it to the console below your code—that's why it's called console.log()! This is commonly called printing out. ● console.log(2 * 5) ● console.log("Hello")
  • 12. Try it yourself.. 1. <html> 2. <head><script> 3. confirm('This is an example of using JS to create some interaction on a website. Click OK to continue!'); 4. console.log(10*10); 5. console.log("Lets start..."); 6. </script></head> 7. <body></body> 8. </html>
  • 13. Comparisons So far we've learned about three data types: ● strings (e.g. "dogs go woof!") ● numbers (e.g. 4, 10) ● booleans (e.g. false, 5 > 4) Now let's learn more about comparison operators.
  • 14. List of comparison operators: > Greater than < Less than <= Less than or equal to >= Greater than or equal to === Equal to !== Not equal to Try to use each of the operators above ● console.log(15 4); // 15 > 4 evaluates to true, so true is printed. // Fill in with >, <, === so that the following print out true: ● console.log("Xiao Hui".length 122); ● console.log("Goody Donaldson".length 8); ● console.log(8*2 16); Choose the correct comparison operator to make each of the four statements print out true.
  • 15. List of comparison operators: > Greater than < Less than <= Less than or equal to >= Greater than or equal to === Equal to !== Not equal to Try to use each of the operators above ● console.log(15 > 4); // 15 > 4 evaluates to true, so true is printed. // Fill in with >, <, === so that the following print out true: ● console.log("Xiao Hui".length < 122); ● console.log("Goody Donaldson".length > 8); ● console.log(8*2 === 16); Choose the correct comparison operator to make each of the four statements print out true.
  • 16. Variables We have learned how to do a few things now: make strings,numbers, do basic math. Not bad for a day's work! To do more complex coding, we need a way to 'save' the values from our coding. We do this by defining a variable with a specific, case-sensitive name. Once you create (or declare) a variable as having a particular name, you can then call up that value by typing the variable name. Syntax: var varName = data;
  • 17. Variables.. Example: ● var myName = "Leng"; ● var isOdd = true; Task ● Create a variable called myAge and type in your age.
  • 18. Task Follow the instructions in the comments in the code to continue. 1. // Declare a variable on line 3 called 2. // myCountry and give it a string value. 3. // Use console.log to print out the length of the variable myCountry. 4. // Use console.log to print out the first three letters of myCountry.
  • 19. Task Follow the instructions in the comments in the code to continue. 1. // Declare a variable on line 3 called 2. // myCountry and give it a string value. 3. var myCountry="india" 4. // Use console.log to print out the length of the variable myCountry. 5. console.log(myCountry.length); 6. // Use console.log to print out the first three letters of myCountry. 7. console.log(myCountry.substring(0,3));
  • 20. Change variable values So far, we've seen ● how to create a variable ● how to use a variable Let's now see how to change a variable's value. A variable's value is easily changed. Just pretend you are creating a new variable while using the same name of the existing variable! Example: var myAge = "Thirty"; myAge = "Thirty-one"; Now the value of myAge is "Thirty-one"!
  • 21. typeof() You can use the JavaScript typeof operator to find the type of a JavaScript variable. 1. <!DOCTYPE html> 2. <html> 3. <head> 4. <script> 5. var x ="Cybersquare"+ 2017; 6. var myvar=5; 7. var bool =true; 8. alert(typeof myvar); //alerts "number" 9. alert(typeof x) 10. </script> 11. </head> 12. <body> 13. <p>You can use the JavaScript typeof operator to find the type of a JavaScript variable.</p> 14. </body> 15. </html>
  • 22. Conclusion Let's do a quick review! ● Datatypes ● Variables ● Manipulating numbers & strings ● Manipulating numbers & strings