Variables
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Variables

on

  • 713 views

 

Statistics

Views

Total Views
713
Views on SlideShare
713
Embed Views
0

Actions

Likes
0
Downloads
4
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Variables Presentation Transcript

  • 1. READING IN USER INPUT ANDDISPLAYING 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 boxDocument.write result usingparseInt 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 * distancedocument.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 * distancealert("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 * distancealert("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 * distancealert("The amount of work done on the barbell is"+work+" Joules");document.write("Work= "+work+" meters");</script></body></html>
  • 11. COMPUQUIZWrite 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. COMPUQUIZB. 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 ina. Fahrenheit to CelsiusF= ?C= (F-32)* 5/9b. Celsius to KelvinC= ?K= C + 273.15
  • 14. Assignment2. 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