SlideShare a Scribd company logo
READING IN USER INPUT AND
DISPLAYING IT ON THE SCREEN
     JavaScript Variable
JAVASCRIPT TERMS/RULES TO
             REMEMBER
• A JavaScript command used to display the
  exact text of an statement.
• It is used to alert the user for some important
  message.
• It is used if you want the user to accept
  something.
• It is a symbol or other character indicating an
  operation that acts on one or more elements.
• It is used to hold values and expressions.
JAVASCRIPT TERMS/RULES TO
               REMEMBER
• = (equal sign) It a symbol used to assign values.
• The parseFloat() function parses a string and returns a
  floating point number.
• This function determines if the first character in the
  specified string is a number. If it is, it parses the string
  until it reaches the end of the number, and returns the
  number as a number, not as a string.
• Note: Only the first number in the string is returned! (“43” and
  “88”) only the “43” will be converted.
• Note: Leading and trailing spaces are allowed.
• Note: If the first character cannot be converted to a number,
  parseFloat() returns NaN. (“Age 40”) 40 will not be converted into
  number because the 1st character is Age, so it will return as NaN
JAVASCRIPT TERMS/RULES TO
             REMEMBER
• Statement is enclosed in an () parenthesis and a
  quotation marks “”.
• (“Answer“+variablename+” is”) – used to get the
  value of the variable. (with statement)
• (“”+variablename+””)- without statement.
• prompt(“Enter number “, ” “)- “, ” means nothing.
• (“nstatement” ,parseInt(variable name)- used
  this to display the result to whole numbers
  (Integers) ); but not round off
• (“ ”,parseInt(variable name));- used if no
  statement
Example of source code with parseInt
               function
• <html>
• <body>
• <script>
• var x= 74
• var y= 45
• var z= x/y
• alert(""+z+"");
• document.write("",parseInt(z));
• </script>
• </body>
• </html>
Web browser result alert box
Document.write result using
parseInt function = 1
EXERCISES
• Write the JavaScript code.
1. A 100 N (force) barbell is lifted to a height of
   2 meters (distance). How much (work) is
   done on the barbell?.
•   Given:
•   force = “100 N”
•   distance= “2 meters”
•   work= force * distance
•   Directly on the page using document.write
•   or Display on the alert box or a prompt box
Directly on the page using document.write
<html>
<head><title>JS</title>
</head>
<body>
<script>
var force= parseFloat("100 N")
var distance= parseFloat("2 meters")
var work= force * distance
document.write("The amount of work done on the barbell
   is"+work+"Joules");
</script>
</body>
</html>
Using Alert box
<html>
<head><title>JS</title>
</head>
<body>
<script>
var force= parseFloat("100 N")
var distance= parseFloat("2 meters")
var work= force * distance
alert("The amount of work done on the barbell is"+work+"Joules");
</script>
</body>
</html>
Using Prompt box
<html>
<head><title>JS</title>
</head>
<body>
<script>
var force= parseFloat(prompt("Enter force"," "));
var distance= parseFloat(prompt("Enter distance"," "));
var work= force * distance
alert("The amount of work done on the barbell is"+work+" Joules");
</script>
</body>
</html>
Using prompt box and document.write
<html>
<head><title>JS</title></head>
<body><script>
var force= parseFloat(prompt("Enter force"," "));
document.write("Force= "+force+" N");
var distance= parseFloat(prompt("Enter distance"," "));
document.write("Distance= "+distance+" meters");
var work= force * distance
alert("The amount of work done on the barbell is"+work+" Joules");
document.write("Work= "+work+" meters");
</script></body></html>
COMPUQUIZ
Write the JavaScript source code. Display the
  result using either document write, alert box
  or prompt box.
A. Determine the density at a 50 cubic
  centimeter (volume), 500 gram gold bar
  (mass).
(density) is equal to mass divided by volume.
COMPUQUIZ
B. Write the source code to get the following
  users data using a prompt box and document
  write.
• Name
• Age
• Birthday
• Address
• Contact Number
Assignment
 Prepare this using intermediate paper or bond paper.

• Using JavaScript write the source code using
   prompt box , alert box and document.write.
1. Converts the user-specified temperature reading
    in
a. Fahrenheit to Celsius
F= ?
C= (F-32)* 5/9
b. Celsius to Kelvin
C= ?
K= C + 273.15
Assignment
2. Using JavaScript write the source code to get
  the users data below using prompt box , alert
  box and document.write.

•   Name
•   School
•   Year Level
•   Section

More Related Content

What's hot

Data Type Conversion in C++
Data Type Conversion in C++Data Type Conversion in C++
Data Type Conversion in C++
Danial Mirza
 
Visual studio 2008
Visual studio 2008Visual studio 2008
Visual studio 2008
Luis Enrique
 
Performing calculations using java script
Performing calculations using java scriptPerforming calculations using java script
Performing calculations using java script
Jesus Obenita Jr.
 

What's hot (20)

Clojure basics
Clojure basicsClojure basics
Clojure basics
 
Presentatioon on type conversion and escape characters
Presentatioon on type conversion and escape charactersPresentatioon on type conversion and escape characters
Presentatioon on type conversion and escape characters
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheory
 
Data Type Conversion in C++
Data Type Conversion in C++Data Type Conversion in C++
Data Type Conversion in C++
 
Functional Programming With Scala
Functional Programming With ScalaFunctional Programming With Scala
Functional Programming With Scala
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++
 
CSEG1001 Unit 5 Structure and Unions
CSEG1001 Unit 5 Structure and UnionsCSEG1001 Unit 5 Structure and Unions
CSEG1001 Unit 5 Structure and Unions
 
Visual studio 2008
Visual studio 2008Visual studio 2008
Visual studio 2008
 
CSEG1001Unit 3 Arrays and Strings
CSEG1001Unit 3 Arrays and StringsCSEG1001Unit 3 Arrays and Strings
CSEG1001Unit 3 Arrays and Strings
 
Python functions part12
Python functions  part12Python functions  part12
Python functions part12
 
VISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VISUAL BASIC 6 - CONTROLS AND DECLARATIONSVISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VISUAL BASIC 6 - CONTROLS AND DECLARATIONS
 
Templates
TemplatesTemplates
Templates
 
function, storage class and array and strings
 function, storage class and array and strings function, storage class and array and strings
function, storage class and array and strings
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
Create and analyse programs
Create and analyse programsCreate and analyse programs
Create and analyse programs
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
03 function overloading
03 function overloading03 function overloading
03 function overloading
 
Knolx session
Knolx sessionKnolx session
Knolx session
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Performing calculations using java script
Performing calculations using java scriptPerforming calculations using java script
Performing calculations using java script
 

Viewers also liked (6)

Shore
ShoreShore
Shore
 
Presentation
PresentationPresentation
Presentation
 
Java scripts
Java scriptsJava scripts
Java scripts
 
Spintronics
SpintronicsSpintronics
Spintronics
 
Basics java scripts
Basics java scriptsBasics java scripts
Basics java scripts
 
Groovy scripts with Groovy
Groovy scripts with GroovyGroovy scripts with Groovy
Groovy scripts with Groovy
 

Similar to Variables

Similar to Variables (20)

Variables 2
Variables 2Variables 2
Variables 2
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
 
Java script basics
Java script basicsJava script basics
Java script basics
 
JavaScript.pptx
JavaScript.pptxJavaScript.pptx
JavaScript.pptx
 
Client sidescripting javascript
Client sidescripting javascriptClient sidescripting javascript
Client sidescripting javascript
 
Java Fx
Java FxJava Fx
Java Fx
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
 
Pythonintro
PythonintroPythonintro
Pythonintro
 
Console I/o & basics of array and strings.pptx
Console I/o & basics of array and strings.pptxConsole I/o & basics of array and strings.pptx
Console I/o & basics of array and strings.pptx
 
Unit I - 1R introduction to R program.pptx
Unit I - 1R introduction to R program.pptxUnit I - 1R introduction to R program.pptx
Unit I - 1R introduction to R program.pptx
 
C
CC
C
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
 
BITM3730 10-17.pptx
BITM3730 10-17.pptxBITM3730 10-17.pptx
BITM3730 10-17.pptx
 

More from Jesus Obenita Jr.

Session 2 test construction.mt's
Session 2   test construction.mt'sSession 2   test construction.mt's
Session 2 test construction.mt's
Jesus Obenita Jr.
 

More from Jesus Obenita Jr. (20)

Organization and management 3 a Evolution of Management Theory
Organization and management 3 a Evolution of Management TheoryOrganization and management 3 a Evolution of Management Theory
Organization and management 3 a Evolution of Management Theory
 
Organization and management 2 Management Function
Organization and management 2 Management FunctionOrganization and management 2 Management Function
Organization and management 2 Management Function
 
Organization and management 1
Organization and management 1Organization and management 1
Organization and management 1
 
Designing web page marquee and img tag
Designing web page  marquee and img tagDesigning web page  marquee and img tag
Designing web page marquee and img tag
 
Ms excel 2013 formatting worksheets
Ms excel 2013 formatting worksheetsMs excel 2013 formatting worksheets
Ms excel 2013 formatting worksheets
 
Ms excel 2013 data management
Ms excel 2013 data managementMs excel 2013 data management
Ms excel 2013 data management
 
Microsoft Excel introduction
Microsoft Excel introductionMicrosoft Excel introduction
Microsoft Excel introduction
 
Word 2013 working with pictures
Word 2013 working with picturesWord 2013 working with pictures
Word 2013 working with pictures
 
Word 2013 Formatting Page
Word 2013 Formatting PageWord 2013 Formatting Page
Word 2013 Formatting Page
 
Word 2013 8
Word 2013 8Word 2013 8
Word 2013 8
 
Ms word 2013 7
Ms word 2013 7Ms word 2013 7
Ms word 2013 7
 
Ms word 2013 6
Ms word 2013 6Ms word 2013 6
Ms word 2013 6
 
Ms word 2013 4
Ms word 2013 4Ms word 2013 4
Ms word 2013 4
 
Ms word 2013 2
Ms word 2013 2Ms word 2013 2
Ms word 2013 2
 
Ms word 2013
Ms word 2013Ms word 2013
Ms word 2013
 
Parts of the ms word 2013 screen and
Parts of the ms word 2013 screen andParts of the ms word 2013 screen and
Parts of the ms word 2013 screen and
 
Word processor
Word processorWord processor
Word processor
 
Session 2 test construction.mt's
Session 2   test construction.mt'sSession 2   test construction.mt's
Session 2 test construction.mt's
 
Cooking ingredients
Cooking ingredientsCooking ingredients
Cooking ingredients
 
Color theory
Color theoryColor theory
Color theory
 

Recently uploaded

Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training Report
Avinash Rai
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 

Recently uploaded (20)

Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resources
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training Report
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptxSolid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx
 
Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resources
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
NCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdfNCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Forest and Wildlife Resources Class 10 Free Study Material PDF
Forest and Wildlife Resources Class 10 Free Study Material PDFForest and Wildlife Resources Class 10 Free Study Material PDF
Forest and Wildlife Resources Class 10 Free Study Material PDF
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
 

Variables

  • 1. READING IN USER INPUT AND DISPLAYING IT ON THE SCREEN JavaScript Variable
  • 2. JAVASCRIPT TERMS/RULES TO REMEMBER • A JavaScript command used to display the exact text of an statement. • It is used to alert the user for some important message. • It is used if you want the user to accept something. • It is a symbol or other character indicating an operation that acts on one or more elements. • It is used to hold values and expressions.
  • 3. JAVASCRIPT TERMS/RULES TO REMEMBER • = (equal sign) It a symbol used to assign values. • The parseFloat() function parses a string and returns a floating point number. • This function determines if the first character in the specified string is a number. If it is, it parses the string until it reaches the end of the number, and returns the number as a number, not as a string. • Note: Only the first number in the string is returned! (“43” and “88”) only the “43” will be converted. • Note: Leading and trailing spaces are allowed. • Note: If the first character cannot be converted to a number, parseFloat() returns NaN. (“Age 40”) 40 will not be converted into number because the 1st character is Age, so it will return as NaN
  • 4. JAVASCRIPT TERMS/RULES TO REMEMBER • Statement is enclosed in an () parenthesis and a quotation marks “”. • (“Answer“+variablename+” is”) – used to get the value of the variable. (with statement) • (“”+variablename+””)- without statement. • prompt(“Enter number “, ” “)- “, ” means nothing. • (“nstatement” ,parseInt(variable name)- used this to display the result to whole numbers (Integers) ); but not round off • (“ ”,parseInt(variable name));- used if no statement
  • 5. Example of source code with parseInt function • <html> • <body> • <script> • var x= 74 • var y= 45 • var z= x/y • alert(""+z+""); • document.write("",parseInt(z)); • </script> • </body> • </html> Web browser result alert box Document.write result using parseInt function = 1
  • 6. EXERCISES • Write the JavaScript code. 1. A 100 N (force) barbell is lifted to a height of 2 meters (distance). How much (work) is done on the barbell?. • Given: • force = “100 N” • distance= “2 meters” • work= force * distance • Directly on the page using document.write • or Display on the alert box or a prompt box
  • 7. Directly on the page using document.write <html> <head><title>JS</title> </head> <body> <script> var force= parseFloat("100 N") var distance= parseFloat("2 meters") var work= force * distance document.write("The amount of work done on the barbell is"+work+"Joules"); </script> </body> </html>
  • 8. Using Alert box <html> <head><title>JS</title> </head> <body> <script> var force= parseFloat("100 N") var distance= parseFloat("2 meters") var work= force * distance alert("The amount of work done on the barbell is"+work+"Joules"); </script> </body> </html>
  • 9. Using Prompt box <html> <head><title>JS</title> </head> <body> <script> var force= parseFloat(prompt("Enter force"," ")); var distance= parseFloat(prompt("Enter distance"," ")); var work= force * distance alert("The amount of work done on the barbell is"+work+" Joules"); </script> </body> </html>
  • 10. Using prompt box and document.write <html> <head><title>JS</title></head> <body><script> var force= parseFloat(prompt("Enter force"," ")); document.write("Force= "+force+" N"); var distance= parseFloat(prompt("Enter distance"," ")); document.write("Distance= "+distance+" meters"); var work= force * distance alert("The amount of work done on the barbell is"+work+" Joules"); document.write("Work= "+work+" meters"); </script></body></html>
  • 11. COMPUQUIZ Write the JavaScript source code. Display the result using either document write, alert box or prompt box. A. Determine the density at a 50 cubic centimeter (volume), 500 gram gold bar (mass). (density) is equal to mass divided by volume.
  • 12. COMPUQUIZ B. Write the source code to get the following users data using a prompt box and document write. • Name • Age • Birthday • Address • Contact Number
  • 13. Assignment Prepare this using intermediate paper or bond paper. • Using JavaScript write the source code using prompt box , alert box and document.write. 1. Converts the user-specified temperature reading in a. Fahrenheit to Celsius F= ? C= (F-32)* 5/9 b. Celsius to Kelvin C= ? K= C + 273.15
  • 14. Assignment 2. Using JavaScript write the source code to get the users data below using prompt box , alert box and document.write. • Name • School • Year Level • Section