Your SlideShare is downloading. ×
0
READING IN USER INPUT ANDDISPLAYING IT ON THE SCREEN     JavaScript Variable
JAVASCRIPT TERMS/RULES TO             REMEMBER• A JavaScript command used to display the  exact text of an statement.• It ...
JAVASCRIPT TERMS/RULES TO               REMEMBER• = (equal sign) It a symbol used to assign values.• The parseFloat() func...
JAVASCRIPT TERMS/RULES TO             REMEMBER• Statement is enclosed in an () parenthesis and a  quotation marks “”.• (“A...
Example of source code with parseInt               function• <html>• <body>• <script>• var x= 74• var y= 45• var z= x/y• a...
EXERCISES• Write the JavaScript code.1. A 100 N (force) barbell is lifted to a height of   2 meters (distance). How much (...
Directly on the page using document.write<html><head><title>JS</title></head><body><script>var force= parseFloat("100 N")v...
Using Alert box<html><head><title>JS</title></head><body><script>var force= parseFloat("100 N")var distance= parseFloat("2...
Using Prompt box<html><head><title>JS</title></head><body><script>var force= parseFloat(prompt("Enter force"," "));var dis...
Using prompt box and document.write<html><head><title>JS</title></head><body><script>var force= parseFloat(prompt("Enter f...
COMPUQUIZWrite the JavaScript source code. Display the  result using either document write, alert box  or prompt box.A. De...
COMPUQUIZB. Write the source code to get the following  users data using a prompt box and document  write.• Name• Age• Bir...
Assignment Prepare this using intermediate paper or bond paper.• Using JavaScript write the source code using   prompt box...
Assignment2. Using JavaScript write the source code to get  the users data below using prompt box , alert  box and documen...
Upcoming SlideShare
Loading in...5
×

Variables

442

Published on

Published in: Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
442
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
5
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Variables"

  1. 1. READING IN USER INPUT ANDDISPLAYING IT ON THE SCREEN JavaScript Variable
  2. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×