SlideShare ist ein Scribd-Unternehmen logo
1 von 14
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

Weitere ähnliche Inhalte

Was ist angesagt?

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.
 

Was ist angesagt? (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
 

Andere mochten auch (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
 

Ähnlich wie Variables

Ähnlich wie 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
 

Mehr von 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.
 

Mehr von 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
 

Kürzlich hochgeladen

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Kürzlich hochgeladen (20)

Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 

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