1 / 19

Javascript : variables and parameters

Javascript : variables and parameters. 20 March 2014. Remember javascript is very, very case sensitive. javascript console. Shows errors Lets you write messages and intermediate results console.log ( whatever helps );. Using jsfiddle. Validation Testing Cut and paste

micol
Download Presentation

Javascript : variables and parameters

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Javascript:variables and parameters 20 March 2014

  2. Rememberjavascriptis very, very case sensitive

  3. javascript console • Shows errors • Lets you write messages and intermediate results console.log ( whatever helps);

  4. Using jsfiddle • Validation • Testing • Cut and paste • Add HTML and CSS if you are having problems

  5. What we want to do

  6. Form with input, button, output HTML JavaScript

  7. Add data HTML JavaScript

  8. Push button and input data sent to javascript HTML JavaScript

  9. Javascript uses the data to create a new result HTML JavaScript

  10. And moves it to the output location HTML JavaScript

  11. How do we do it?

  12. variables • A place to hold a value • Mailbox: know where to pick up my mail; don’t know what’s in it • How to define? varname; varname = initial-value;

  13. Assignment statements target = new-value; • CHANGE the value of the target variable TO the new-value • new-value can be a constant, a variable, or an expression x = 3; x = y; x = x+ 5;

  14. Using values from forms • Value in the form can be treated just like a variable! • Giving it a value • User input • Assign it a value in an onclick • Define it in the HTML

  15. FUNCTION: collection of instructions HTML JAVASCRIPT (function.js) function doit () { alert(“Hi!”); } <head> <script src=“function.js”></script> </head> <body> <button type=“button” onclick=“doit();”> </body>

  16. parameters • Just a special type of variable • Something that you hand to the function • Q: Many users: how do you name? • A: Give it its OWN names to use locally • Q: How do you match up? • A: By POSITION

  17. FUNCTION with parameters HTML JAVASCRIPT (function.js) function doit(a,b) { var c = a*b); alert(“product is ”+c); } <head> <script src=“function.js”></script> </head> <body> <button type=“button” onclick=“doit(3,5);”> </body>

  18. Return value return (value); • Want to get information BACK to HTML • With a return, the function has a VALUE • Can be used anywhere you can use a constant or variable • Alert • Assignment statement

  19. FUNCTION with return HTML JAVASCRIPT (function.js) function doit(a,b) { var c = a*b); return(c); } <head> <script src=“function.js”></script> </head> <body> <button type=“button” onclick=“alert(doit(3,5));”> </body>

More Related