Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Introduction to JavaScript

131 views

Published on

Introduction to JavaScript for members of the Erasmus+ founded project GAMES

Published in: Education
  • Unlock Her Legs(Official) $69 | Get 90% Off + 8 Special Bonus? ♥♥♥ http://t.cn/AiurDrZp
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • ★★ How Long Does She Want You to Last? ★★ A recent study proved that the average man lasts just 2-5 minutes in bed (during intercourse). The study also showed that many women need at least 7-10 minutes of intercourse to reach "The Big O" - and, worse still... 30% of women never get there during intercourse. Clearly, most men are NOT fulfilling there women's needs in bed. Now, as I've said many times - how long you can last is no guarantee of being a GREAT LOVER. But, not being able to last 20, 30 minutes or more, is definitely a sign that you're not going to "set your woman's world on fire" between the sheets. Question is: "What can you do to last longer?" Well, one of the best recommendations I can give you today is to read THIS report. In it, you'll discover a detailed guide to an Ancient Taoist Thrusting Technique that can help any man to last much longer in bed. I can vouch 100% for the technique because my husband has been using it for years :) Here's the link to the report ➤➤ https://tinyurl.com/rockhardxx
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Introduction to JavaScript

  1. 1. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Introduction to JavaScript Apostolos Syropoulos Xanthi, Greece asyropoulos@yahoo.com Introduction to JavaScript for members of the Erasmus+ founded project GAMES
  2. 2. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Presentation Outline 1 Programming Languages 2 Basics of JavaScript 3 Expressions and Operators 4 Basic Commands 5 Defining New Functions 6 Finale
  3. 3. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is a Programming Language?
  4. 4. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is a Programming Language? A formalism or formal notion used to instruct a computer to perform a computational task.
  5. 5. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is a Programming Language? A formalism or formal notion used to instruct a computer to perform a computational task. Roughly, a computational task is an abstract, mathematical in a sense, task.
  6. 6. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is a Programming Language? A formalism or formal notion used to instruct a computer to perform a computational task. Roughly, a computational task is an abstract, mathematical in a sense, task. Philosophical question: Is falling in love a computational task?
  7. 7. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is a Programming Language? A formalism or formal notion used to instruct a computer to perform a computational task. Roughly, a computational task is an abstract, mathematical in a sense, task. Philosophical question: Is falling in love a computational task? Surprisingly, computationalism—the view that mental states are computational states—has many followers.
  8. 8. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is a Programming Language? A formalism or formal notion used to instruct a computer to perform a computational task. Roughly, a computational task is an abstract, mathematical in a sense, task. Philosophical question: Is falling in love a computational task? Surprisingly, computationalism—the view that mental states are computational states—has many followers. On the other hand, Jaak Panksepp asks: Could you compute me an orgasm?
  9. 9. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is a Programming Language? A formalism or formal notion used to instruct a computer to perform a computational task. Roughly, a computational task is an abstract, mathematical in a sense, task. Philosophical question: Is falling in love a computational task? Surprisingly, computationalism—the view that mental states are computational states—has many followers. On the other hand, Jaak Panksepp asks: Could you compute me an orgasm? Back to business: Computers can calculate and enumerate and that’s what we do with programming languages.
  10. 10. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is a Programming Language? A formalism or formal notion used to instruct a computer to perform a computational task. Roughly, a computational task is an abstract, mathematical in a sense, task. Philosophical question: Is falling in love a computational task? Surprisingly, computationalism—the view that mental states are computational states—has many followers. On the other hand, Jaak Panksepp asks: Could you compute me an orgasm? Back to business: Computers can calculate and enumerate and that’s what we do with programming languages. Niklaus Wirth did not like the term programming language.
  11. 11. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Characteristics of Programming Languages
  12. 12. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Characteristics of Programming Languages How computational tasks are described?
  13. 13. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Characteristics of Programming Languages How computational tasks are described? By a sequence of commands? The language is imperative.
  14. 14. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Characteristics of Programming Languages How computational tasks are described? By a sequence of commands? The language is imperative. By objects and their interactions? The language is object-oriented.
  15. 15. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Characteristics of Programming Languages How computational tasks are described? By a sequence of commands? The language is imperative. By objects and their interactions? The language is object-oriented. By functions and their composition? The language is functional.
  16. 16. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Characteristics of Programming Languages How computational tasks are described? By a sequence of commands? The language is imperative. By objects and their interactions? The language is object-oriented. By functions and their composition? The language is functional. By a set of sentences in logical form? Then it is a logic programming language
  17. 17. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Characteristics of Programming Languages How computational tasks are described? By a sequence of commands? The language is imperative. By objects and their interactions? The language is object-oriented. By functions and their composition? The language is functional. By a set of sentences in logical form? Then it is a logic programming language Specifying a programming language means to: describe its syntax and its semantics.
  18. 18. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Characteristics of Programming Languages How computational tasks are described? By a sequence of commands? The language is imperative. By objects and their interactions? The language is object-oriented. By functions and their composition? The language is functional. By a set of sentences in logical form? Then it is a logic programming language Specifying a programming language means to: describe its syntax and its semantics. Syntax: the way we arrange “linguistic” elements in a program.
  19. 19. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Characteristics of Programming Languages How computational tasks are described? By a sequence of commands? The language is imperative. By objects and their interactions? The language is object-oriented. By functions and their composition? The language is functional. By a set of sentences in logical form? Then it is a logic programming language Specifying a programming language means to: describe its syntax and its semantics. Syntax: the way we arrange “linguistic” elements in a program. Semantics: the computational effect of each structure.
  20. 20. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Some popular programming languages
  21. 21. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Some popular programming languages Old languages:
  22. 22. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Some popular programming languages Old languages: FORTRAN,
  23. 23. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Some popular programming languages Old languages: FORTRAN, COBOL,
  24. 24. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Some popular programming languages Old languages: FORTRAN, COBOL, PL/1,
  25. 25. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Some popular programming languages Old languages: FORTRAN, COBOL, PL/1, Algol68,
  26. 26. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Some popular programming languages Old languages: FORTRAN, COBOL, PL/1, Algol68, BASIC,
  27. 27. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Some popular programming languages Old languages: FORTRAN, COBOL, PL/1, Algol68, BASIC, LISP,
  28. 28. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Some popular programming languages Old languages: FORTRAN, COBOL, PL/1, Algol68, BASIC, LISP, Pascal.
  29. 29. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Some popular programming languages Old languages: FORTRAN, COBOL, PL/1, Algol68, BASIC, LISP, Pascal. Timeless languages:
  30. 30. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Some popular programming languages Old languages: FORTRAN, COBOL, PL/1, Algol68, BASIC, LISP, Pascal. Timeless languages: C,
  31. 31. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Some popular programming languages Old languages: FORTRAN, COBOL, PL/1, Algol68, BASIC, LISP, Pascal. Timeless languages: C, C++,
  32. 32. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Some popular programming languages Old languages: FORTRAN, COBOL, PL/1, Algol68, BASIC, LISP, Pascal. Timeless languages: C, C++, Ada,
  33. 33. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Some popular programming languages Old languages: FORTRAN, COBOL, PL/1, Algol68, BASIC, LISP, Pascal. Timeless languages: C, C++, Ada, Prolog,
  34. 34. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Some popular programming languages Old languages: FORTRAN, COBOL, PL/1, Algol68, BASIC, LISP, Pascal. Timeless languages: C, C++, Ada, Prolog, SML.
  35. 35. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Some popular programming languages Old languages: FORTRAN, COBOL, PL/1, Algol68, BASIC, LISP, Pascal. Timeless languages: C, C++, Ada, Prolog, SML. Modern languages:
  36. 36. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Some popular programming languages Old languages: FORTRAN, COBOL, PL/1, Algol68, BASIC, LISP, Pascal. Timeless languages: C, C++, Ada, Prolog, SML. Modern languages: Java,
  37. 37. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Some popular programming languages Old languages: FORTRAN, COBOL, PL/1, Algol68, BASIC, LISP, Pascal. Timeless languages: C, C++, Ada, Prolog, SML. Modern languages: Java, JavaScript,
  38. 38. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Some popular programming languages Old languages: FORTRAN, COBOL, PL/1, Algol68, BASIC, LISP, Pascal. Timeless languages: C, C++, Ada, Prolog, SML. Modern languages: Java, JavaScript, Perl,
  39. 39. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Some popular programming languages Old languages: FORTRAN, COBOL, PL/1, Algol68, BASIC, LISP, Pascal. Timeless languages: C, C++, Ada, Prolog, SML. Modern languages: Java, JavaScript, Perl, Python,
  40. 40. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Some popular programming languages Old languages: FORTRAN, COBOL, PL/1, Algol68, BASIC, LISP, Pascal. Timeless languages: C, C++, Ada, Prolog, SML. Modern languages: Java, JavaScript, Perl, Python, Ruby,
  41. 41. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Some popular programming languages Old languages: FORTRAN, COBOL, PL/1, Algol68, BASIC, LISP, Pascal. Timeless languages: C, C++, Ada, Prolog, SML. Modern languages: Java, JavaScript, Perl, Python, Ruby, C#,
  42. 42. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Some popular programming languages Old languages: FORTRAN, COBOL, PL/1, Algol68, BASIC, LISP, Pascal. Timeless languages: C, C++, Ada, Prolog, SML. Modern languages: Java, JavaScript, Perl, Python, Ruby, C#, Haskell.
  43. 43. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Some popular programming languages Old languages: FORTRAN, COBOL, PL/1, Algol68, BASIC, LISP, Pascal. Timeless languages: C, C++, Ada, Prolog, SML. Modern languages: Java, JavaScript, Perl, Python, Ruby, C#, Haskell.
  44. 44. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is Programming?
  45. 45. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is Programming? Programming is the mental activity by which we express the solution to a given (mathematical) problem in some programming language.
  46. 46. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is Programming? Programming is the mental activity by which we express the solution to a given (mathematical) problem in some programming language. The difficult part is to solve the problem with specific tools.
  47. 47. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is Programming? Programming is the mental activity by which we express the solution to a given (mathematical) problem in some programming language. The difficult part is to solve the problem with specific tools. Programming is not something you learn by following a recipe or a method.
  48. 48. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is Programming? Programming is the mental activity by which we express the solution to a given (mathematical) problem in some programming language. The difficult part is to solve the problem with specific tools. Programming is not something you learn by following a recipe or a method. Programming is both a craft and a science.
  49. 49. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is Programming? Programming is the mental activity by which we express the solution to a given (mathematical) problem in some programming language. The difficult part is to solve the problem with specific tools. Programming is not something you learn by following a recipe or a method. Programming is both a craft and a science. It is a craft (or art!) because there are no rules of thumb that one can follow to solve a problem.
  50. 50. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is Programming? Programming is the mental activity by which we express the solution to a given (mathematical) problem in some programming language. The difficult part is to solve the problem with specific tools. Programming is not something you learn by following a recipe or a method. Programming is both a craft and a science. It is a craft (or art!) because there are no rules of thumb that one can follow to solve a problem. A programmer is a scientist if mathematicians are scientists.
  51. 51. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is Programming? Programming is the mental activity by which we express the solution to a given (mathematical) problem in some programming language. The difficult part is to solve the problem with specific tools. Programming is not something you learn by following a recipe or a method. Programming is both a craft and a science. It is a craft (or art!) because there are no rules of thumb that one can follow to solve a problem. A programmer is a scientist if mathematicians are scientists. Intuition plays a very important when solving a problem.
  52. 52. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is Programming? Programming is the mental activity by which we express the solution to a given (mathematical) problem in some programming language. The difficult part is to solve the problem with specific tools. Programming is not something you learn by following a recipe or a method. Programming is both a craft and a science. It is a craft (or art!) because there are no rules of thumb that one can follow to solve a problem. A programmer is a scientist if mathematicians are scientists. Intuition plays a very important when solving a problem. The implementation of a solution requires the knowledge of common techniques and practicers.
  53. 53. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Steps Involved in Programming
  54. 54. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Steps Involved in Programming Defining the problem.
  55. 55. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Steps Involved in Programming Defining the problem. Outlining and structuring the solution.
  56. 56. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Steps Involved in Programming Defining the problem. Outlining and structuring the solution. Selecting solution methods.
  57. 57. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Steps Involved in Programming Defining the problem. Outlining and structuring the solution. Selecting solution methods. Coding.
  58. 58. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Steps Involved in Programming Defining the problem. Outlining and structuring the solution. Selecting solution methods. Coding. Debugging.
  59. 59. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Steps Involved in Programming Defining the problem. Outlining and structuring the solution. Selecting solution methods. Coding. Debugging. Testing and verifying.
  60. 60. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Steps Involved in Programming Defining the problem. Outlining and structuring the solution. Selecting solution methods. Coding. Debugging. Testing and verifying. Documenting.
  61. 61. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Steps Involved in Programming Defining the problem. Outlining and structuring the solution. Selecting solution methods. Coding. Debugging. Testing and verifying. Documenting. Maintaining the program.
  62. 62. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is JavaScript?
  63. 63. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is JavaScript? It is an object-oriented programming language initially designed and implemented by Netscape.
  64. 64. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is JavaScript? It is an object-oriented programming language initially designed and implemented by Netscape. The language is the most widely used language for client-side scripting of web pages.
  65. 65. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is JavaScript? It is an object-oriented programming language initially designed and implemented by Netscape. The language is the most widely used language for client-side scripting of web pages. HTML5 and all relatively older versions of HTML support tge <script>
  66. 66. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is JavaScript? It is an object-oriented programming language initially designed and implemented by Netscape. The language is the most widely used language for client-side scripting of web pages. HTML5 and all relatively older versions of HTML support tge <script> JavaScript can be used to make dynamic web pages.
  67. 67. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is JavaScript? It is an object-oriented programming language initially designed and implemented by Netscape. The language is the most widely used language for client-side scripting of web pages. HTML5 and all relatively older versions of HTML support tge <script> JavaScript can be used to make dynamic web pages. JavaScript and Java are object-oriented languages but that is their only similarity.
  68. 68. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding JavaScript Code to HTML Content
  69. 69. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding JavaScript Code to HTML Content Here is how we can embed JavaScript code:
  70. 70. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding JavaScript Code to HTML Content Here is how we can embed JavaScript code: <script> JavaScript commands… </script> <noscript> WARNING</noscript>
  71. 71. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding JavaScript Code to HTML Content Here is how we can embed JavaScript code: <script> JavaScript commands… </script> <noscript> WARNING</noscript> Alternatively
  72. 72. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding JavaScript Code to HTML Content Here is how we can embed JavaScript code: <script> JavaScript commands… </script> <noscript> WARNING</noscript> Alternatively … <head> <title>My Page</title> <script src="common.js"> </script> </head> <body> …
  73. 73. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A Complete Example
  74. 74. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A Complete Example Here i a complete example:
  75. 75. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A Complete Example Here i a complete example: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Example</title> </head><body> <script> document.write("Hello, net!") </script> <noscript>No JavaScript support.</noscript> <p>That's all, folks.</p> </body> </html>
  76. 76. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A Complete Example Here i a complete example: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Example</title> </head><body> <script> document.write("Hello, net!") </script> <noscript>No JavaScript support.</noscript> <p>That's all, folks.</p> </body> </html> Open your text-editor, type the code, save the file and open it with your browser.
  77. 77. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Values
  78. 78. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Values Numbers, that is, quantities like 41 or 3.14159.
  79. 79. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Values Numbers, that is, quantities like 41 or 3.14159. Boolean (logical) values, that is, the values true and false.
  80. 80. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Values Numbers, that is, quantities like 41 or 3.14159. Boolean (logical) values, that is, the values true and false. Sequences of character like "Hello!" that are known as strings.
  81. 81. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Values Numbers, that is, quantities like 41 or 3.14159. Boolean (logical) values, that is, the values true and false. Sequences of character like "Hello!" that are known as strings. A string must be enclosed in either single or double quotation marks, for instance, "John's girlfriend." or 'Mary came!'.
  82. 82. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Values Numbers, that is, quantities like 41 or 3.14159. Boolean (logical) values, that is, the values true and false. Sequences of character like "Hello!" that are known as strings. A string must be enclosed in either single or double quotation marks, for instance, "John's girlfriend." or 'Mary came!'. The value null, which denotes a no value.
  83. 83. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Values Numbers, that is, quantities like 41 or 3.14159. Boolean (logical) values, that is, the values true and false. Sequences of character like "Hello!" that are known as strings. A string must be enclosed in either single or double quotation marks, for instance, "John's girlfriend." or 'Mary came!'. The value null, which denotes a no value. The value undefined, which denotes an undefined value.
  84. 84. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Variables
  85. 85. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Variables A variable is a name that is used to designate a value.
  86. 86. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Variables A variable is a name that is used to designate a value. In mathematics we write 𝜋 to designate the number 3.1415926535897 ….
  87. 87. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Variables A variable is a name that is used to designate a value. In mathematics we write 𝜋 to designate the number 3.1415926535897 …. A variable is actually the name of some storage location where a value is stored.
  88. 88. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Variables A variable is a name that is used to designate a value. In mathematics we write 𝜋 to designate the number 3.1415926535897 …. A variable is actually the name of some storage location where a value is stored. Variables do not designate the same value but time passes may designate a different value.
  89. 89. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Variables A variable is a name that is used to designate a value. In mathematics we write 𝜋 to designate the number 3.1415926535897 …. A variable is actually the name of some storage location where a value is stored. Variables do not designate the same value but time passes may designate a different value. Think of a process that counts objects. In different times, it will hold different values.
  90. 90. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Variables A variable is a name that is used to designate a value. In mathematics we write 𝜋 to designate the number 3.1415926535897 …. A variable is actually the name of some storage location where a value is stored. Variables do not designate the same value but time passes may designate a different value. Think of a process that counts objects. In different times, it will hold different values. The first character of the name of a variable must be a letter
  91. 91. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Variables A variable is a name that is used to designate a value. In mathematics we write 𝜋 to designate the number 3.1415926535897 …. A variable is actually the name of some storage location where a value is stored. Variables do not designate the same value but time passes may designate a different value. Think of a process that counts objects. In different times, it will hold different values. The first character of the name of a variable must be a letter If there are more characters in a name they should be letters, digits, or the symbol _ (underscore).
  92. 92. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using Variables
  93. 93. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using Variables A variable can be introduced with an assignment or a declaration.
  94. 94. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using Variables A variable can be introduced with an assignment or a declaration. Assignment: variable = value.
  95. 95. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using Variables A variable can be introduced with an assignment or a declaration. Assignment: variable = value. Declaration: var variable.
  96. 96. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using Variables A variable can be introduced with an assignment or a declaration. Assignment: variable = value. Declaration: var variable. Thus the command x = 3 assigns the value 3 to variable x.
  97. 97. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using Variables A variable can be introduced with an assignment or a declaration. Assignment: variable = value. Declaration: var variable. Thus the command x = 3 assigns the value 3 to variable x. The command x = x + 1 assigns the current value of x plus 1 to variable x.
  98. 98. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using Variables A variable can be introduced with an assignment or a declaration. Assignment: variable = value. Declaration: var variable. Thus the command x = 3 assigns the value 3 to variable x. The command x = x + 1 assigns the current value of x plus 1 to variable x. The command var y declares variable y and its value becomes undefined.
  99. 99. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using Variables A variable can be introduced with an assignment or a declaration. Assignment: variable = value. Declaration: var variable. Thus the command x = 3 assigns the value 3 to variable x. The command x = x + 1 assigns the current value of x plus 1 to variable x. The command var y declares variable y and its value becomes undefined. Find the final values of the various variables after these commands have been executed. x=4 y=6 z=2*x // * denotes multiplication x=x+1
  100. 100. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons
  101. 101. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons valueA @ valueB, where @ is a comparison operator.
  102. 102. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons valueA @ valueB, where @ is a comparison operator. The standard comparison operators are:
  103. 103. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons valueA @ valueB, where @ is a comparison operator. The standard comparison operators are: == (equal to),
  104. 104. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons valueA @ valueB, where @ is a comparison operator. The standard comparison operators are: == (equal to), != (not equal to),
  105. 105. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons valueA @ valueB, where @ is a comparison operator. The standard comparison operators are: == (equal to), != (not equal to), < (less than),
  106. 106. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons valueA @ valueB, where @ is a comparison operator. The standard comparison operators are: == (equal to), != (not equal to), < (less than), > (greater than),
  107. 107. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons valueA @ valueB, where @ is a comparison operator. The standard comparison operators are: == (equal to), != (not equal to), < (less than), > (greater than), <= (less than or equal to), and
  108. 108. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons valueA @ valueB, where @ is a comparison operator. The standard comparison operators are: == (equal to), != (not equal to), < (less than), > (greater than), <= (less than or equal to), and >= (greater than or equal to).
  109. 109. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons valueA @ valueB, where @ is a comparison operator. The standard comparison operators are: == (equal to), != (not equal to), < (less than), > (greater than), <= (less than or equal to), and >= (greater than or equal to). Suppose that x = 5 and var y were just executed. Then,
  110. 110. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons valueA @ valueB, where @ is a comparison operator. The standard comparison operators are: == (equal to), != (not equal to), < (less than), > (greater than), <= (less than or equal to), and >= (greater than or equal to). Suppose that x = 5 and var y were just executed. Then, x == 5 evaluates to true;
  111. 111. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons valueA @ valueB, where @ is a comparison operator. The standard comparison operators are: == (equal to), != (not equal to), < (less than), > (greater than), <= (less than or equal to), and >= (greater than or equal to). Suppose that x = 5 and var y were just executed. Then, x == 5 evaluates to true; x != 5 evaluates to false;
  112. 112. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons valueA @ valueB, where @ is a comparison operator. The standard comparison operators are: == (equal to), != (not equal to), < (less than), > (greater than), <= (less than or equal to), and >= (greater than or equal to). Suppose that x = 5 and var y were just executed. Then, x == 5 evaluates to true; x != 5 evaluates to false; x < 5 evaluates to true;
  113. 113. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons valueA @ valueB, where @ is a comparison operator. The standard comparison operators are: == (equal to), != (not equal to), < (less than), > (greater than), <= (less than or equal to), and >= (greater than or equal to). Suppose that x = 5 and var y were just executed. Then, x == 5 evaluates to true; x != 5 evaluates to false; x < 5 evaluates to true; y == underfined evaluates to true;
  114. 114. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons valueA @ valueB, where @ is a comparison operator. The standard comparison operators are: == (equal to), != (not equal to), < (less than), > (greater than), <= (less than or equal to), and >= (greater than or equal to). Suppose that x = 5 and var y were just executed. Then, x == 5 evaluates to true; x != 5 evaluates to false; x < 5 evaluates to true; y == underfined evaluates to true; x <= 5 evaluates to true.
  115. 115. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arrays
  116. 116. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arrays An array is a special variable that can hold more than one value at a time.
  117. 117. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arrays An array is a special variable that can hold more than one value at a time. Each value is assigned to an element of an array and one can refer to an array by its index.
  118. 118. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arrays An array is a special variable that can hold more than one value at a time. Each value is assigned to an element of an array and one can refer to an array by its index.
  119. 119. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arrays An array is a special variable that can hold more than one value at a time. Each value is assigned to an element of an array and one can refer to an array by its index. To create an array, write the name of the array, the symbol =, and the values that will be stored to the array in square brackets separated by comma: coffees = ["French Roast", "Columbian", "Kona"]
  120. 120. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arrays An array is a special variable that can hold more than one value at a time. Each value is assigned to an element of an array and one can refer to an array by its index. To create an array, write the name of the array, the symbol =, and the values that will be stored to the array in square brackets separated by comma: coffees = ["French Roast", "Columbian", "Kona"] To print the second element of this array, use the following command: document.writeln(coffees[0])
  121. 121. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Strings
  122. 122. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Strings A sequences of character like "Hello!".
  123. 123. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Strings A sequences of character like "Hello!". A string must be enclosed in quotation marks: either single or double quotation marks.
  124. 124. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Strings A sequences of character like "Hello!". A string must be enclosed in quotation marks: either single or double quotation marks. Strings consist of simple ASCII characters, escape sequences, or Unicode characters.
  125. 125. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Strings A sequences of character like "Hello!". A string must be enclosed in quotation marks: either single or double quotation marks. Strings consist of simple ASCII characters, escape sequences, or Unicode characters. An escape sequence corresponds to a special character that cannot be entered conventionally (e.g., the ESC key).
  126. 126. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Strings A sequences of character like "Hello!". A string must be enclosed in quotation marks: either single or double quotation marks. Strings consist of simple ASCII characters, escape sequences, or Unicode characters. An escape sequence corresponds to a special character that cannot be entered conventionally (e.g., the ESC key). Escape sequences consist of a backslash followed by a single letter (e.g., b).
  127. 127. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Assignment Operators
  128. 128. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Assignment Operators An assignment operator stores the value that is on the right of the operator to the storage location designated by the variable on the left of the operator.
  129. 129. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Assignment Operators An assignment operator stores the value that is on the right of the operator to the storage location designated by the variable on the left of the operator. The basic assignment operators are:
  130. 130. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Assignment Operators An assignment operator stores the value that is on the right of the operator to the storage location designated by the variable on the left of the operator. The basic assignment operators are: The expression x += y is shorthand for x = x + y.
  131. 131. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Assignment Operators An assignment operator stores the value that is on the right of the operator to the storage location designated by the variable on the left of the operator. The basic assignment operators are: The expression x += y is shorthand for x = x + y. Similarly, x -= y is shorthand for x = x - y;
  132. 132. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Assignment Operators An assignment operator stores the value that is on the right of the operator to the storage location designated by the variable on the left of the operator. The basic assignment operators are: The expression x += y is shorthand for x = x + y. Similarly, x -= y is shorthand for x = x - y; x *= y is shorthand for x = x * y;
  133. 133. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Assignment Operators An assignment operator stores the value that is on the right of the operator to the storage location designated by the variable on the left of the operator. The basic assignment operators are: The expression x += y is shorthand for x = x + y. Similarly, x -= y is shorthand for x = x - y; x *= y is shorthand for x = x * y; x /= y is shorthand for x = x / y; and
  134. 134. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Assignment Operators An assignment operator stores the value that is on the right of the operator to the storage location designated by the variable on the left of the operator. The basic assignment operators are: The expression x += y is shorthand for x = x + y. Similarly, x -= y is shorthand for x = x - y; x *= y is shorthand for x = x * y; x /= y is shorthand for x = x / y; and x %= y is shorthand for x = x % y.
  135. 135. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators
  136. 136. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators x % y
  137. 137. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators x % y Yields the reminder of the integer division of x by y.
  138. 138. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators x % y Yields the reminder of the integer division of x by y. x++
  139. 139. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators x % y Yields the reminder of the integer division of x by y. x++ Yields the value of x and then increases the value of x by one.
  140. 140. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators x % y Yields the reminder of the integer division of x by y. x++ Yields the value of x and then increases the value of x by one. x--
  141. 141. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators x % y Yields the reminder of the integer division of x by y. x++ Yields the value of x and then increases the value of x by one. x-- Yields the value of x and then decreases the value of x by one.
  142. 142. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators x % y Yields the reminder of the integer division of x by y. x++ Yields the value of x and then increases the value of x by one. x-- Yields the value of x and then decreases the value of x by one. ++x
  143. 143. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators x % y Yields the reminder of the integer division of x by y. x++ Yields the value of x and then increases the value of x by one. x-- Yields the value of x and then decreases the value of x by one. ++x Increases the value of x by one and yields this new value.
  144. 144. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators x % y Yields the reminder of the integer division of x by y. x++ Yields the value of x and then increases the value of x by one. x-- Yields the value of x and then decreases the value of x by one. ++x Increases the value of x by one and yields this new value. --x
  145. 145. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators x % y Yields the reminder of the integer division of x by y. x++ Yields the value of x and then increases the value of x by one. x-- Yields the value of x and then decreases the value of x by one. ++x Increases the value of x by one and yields this new value. --x Decreases the value of x by one and yields this new value.
  146. 146. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators x % y Yields the reminder of the integer division of x by y. x++ Yields the value of x and then increases the value of x by one. x-- Yields the value of x and then decreases the value of x by one. ++x Increases the value of x by one and yields this new value. --x Decreases the value of x by one and yields this new value. -x
  147. 147. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators x % y Yields the reminder of the integer division of x by y. x++ Yields the value of x and then increases the value of x by one. x-- Yields the value of x and then decreases the value of x by one. ++x Increases the value of x by one and yields this new value. --x Decreases the value of x by one and yields this new value. -x Yields the opposite of x.
  148. 148. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Boolean Operators
  149. 149. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Boolean Operators x && y
  150. 150. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Boolean Operators x && y = true only if both x and y evaluate to true.
  151. 151. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Boolean Operators x && y = true only if both x and y evaluate to true. x || y
  152. 152. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Boolean Operators x && y = true only if both x and y evaluate to true. x || y = true if either x or y evaluate to true.
  153. 153. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Boolean Operators x && y = true only if both x and y evaluate to true. x || y = true if either x or y evaluate to true. ! x
  154. 154. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Boolean Operators x && y = true only if both x and y evaluate to true. x || y = true if either x or y evaluate to true. ! x = true if x evaluates to false, true otherwise.
  155. 155. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . About Commands in General
  156. 156. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . About Commands in General A command is an instruction given by a user telling a computer to do something.
  157. 157. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . About Commands in General A command is an instruction given by a user telling a computer to do something. Commands are put together by a programmer to achieve a specific task.
  158. 158. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . About Commands in General A command is an instruction given by a user telling a computer to do something. Commands are put together by a programmer to achieve a specific task. The basic commands of the language are:
  159. 159. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . About Commands in General A command is an instruction given by a user telling a computer to do something. Commands are put together by a programmer to achieve a specific task. The basic commands of the language are: Conditional commands: if...else and swicth.
  160. 160. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . About Commands in General A command is an instruction given by a user telling a computer to do something. Commands are put together by a programmer to achieve a specific task. The basic commands of the language are: Conditional commands: if...else and swicth. Repetition commands: for, while, do...while, a labeled command (used in repetition commands without being such a command), the break command and the continue command.
  161. 161. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . About Commands in General A command is an instruction given by a user telling a computer to do something. Commands are put together by a programmer to achieve a specific task. The basic commands of the language are: Conditional commands: if...else and swicth. Repetition commands: for, while, do...while, a labeled command (used in repetition commands without being such a command), the break command and the continue command. Comments.
  162. 162. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The if command
  163. 163. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The if command if (condition){ commands } if (condition){ commands A } else{ commands B } Form (a) Form (b)
  164. 164. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The if command if (condition){ commands } if (condition){ commands A } else{ commands B } Form (a) Form (b) Example if(3>2){ document.write("okey!") else{ document.write("problem!") }
  165. 165. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The switch Command
  166. 166. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The switch Command switch (expression){ case label1: command1; break; case label2: command2; break; … default: commandN; }
  167. 167. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The for Command
  168. 168. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The for Command for (initialization; condition; inc.-dec.){ commands }
  169. 169. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The for Command for (initialization; condition; inc.-dec.){ commands } Example
  170. 170. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The for Command for (initialization; condition; inc.-dec.){ commands } Example var sum = 0; for(i=1; i<=100; i++){ sum += i; } document.write("<p> 1+2+...+100 = ") document.write(sum); document.write("</p>")
  171. 171. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The do-while Command
  172. 172. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The do-while Command do { commands } while (condition)
  173. 173. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The do-while Command do { commands } while (condition) Example
  174. 174. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The do-while Command do { commands } while (condition) Example i=0; do{ i++; document.writeln(i); }while (i<=5);
  175. 175. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The while Command
  176. 176. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The while Command while (condition){ commands }
  177. 177. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The while Command while (condition){ commands } Example
  178. 178. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The while Command while (condition){ commands } Example i=1; while (i<=5){ document.writeln(i); i++; };
  179. 179. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Labels
  180. 180. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Labels label: command
  181. 181. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Labels label: command Example
  182. 182. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Labels label: command Example var str = ""; loop1: for (var i = 0; i < 5; i++) { if (i === 1) { continue loop1; } str = str + i; } documemt.write(str);
  183. 183. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The break command
  184. 184. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The break command break or break label
  185. 185. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The break command break or break label Example
  186. 186. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The break command break or break label Example for (i=0; i < a.length; i++) { if (a[i] == theValue) { break; } }
  187. 187. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The continue command
  188. 188. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The continue command continue or continue label
  189. 189. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The continue command continue or continue label Example
  190. 190. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The continue command continue or continue label Example i = 0 n = 0 while (i < 5) { i++ if (i == 3) { continue } document.write(n); document.write(" ") n += i }
  191. 191. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is a Function?
  192. 192. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is a Function? A set is a collection of things (e.g., numbers, objects, people, etc.).
  193. 193. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is a Function? A set is a collection of things (e.g., numbers, objects, people, etc.). A function is a relation between the elements of two or more sets.
  194. 194. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is a Function? A set is a collection of things (e.g., numbers, objects, people, etc.). A function is a relation between the elements of two or more sets. A function from a set 𝐴 to a set 𝐵 maps every element of 𝐴 to one and only one element of 𝐵.
  195. 195. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is a Function? A set is a collection of things (e.g., numbers, objects, people, etc.). A function is a relation between the elements of two or more sets. A function from a set 𝐴 to a set 𝐵 maps every element of 𝐴 to one and only one element of 𝐵. To define a function mathematically, we have to write something like minus(𝑥) = −𝑥.
  196. 196. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is a Function? A set is a collection of things (e.g., numbers, objects, people, etc.). A function is a relation between the elements of two or more sets. A function from a set 𝐴 to a set 𝐵 maps every element of 𝐴 to one and only one element of 𝐵. To define a function mathematically, we have to write something like minus(𝑥) = −𝑥. The letter 𝑥 is called a parameter, while the 5 in minus(5) is called argument.
  197. 197. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is a Function? A set is a collection of things (e.g., numbers, objects, people, etc.). A function is a relation between the elements of two or more sets. A function from a set 𝐴 to a set 𝐵 maps every element of 𝐴 to one and only one element of 𝐵. To define a function mathematically, we have to write something like minus(𝑥) = −𝑥. The letter 𝑥 is called a parameter, while the 5 in minus(5) is called argument. In computer jargon we say a function returns a value and we mean the value that the function maps its argument.
  198. 198. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . New Functions
  199. 199. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . New Functions To define a function we first type the word function.
  200. 200. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . New Functions To define a function we first type the word function. Then, the name of the function, which should be no different than a variable name.
  201. 201. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . New Functions To define a function we first type the word function. Then, the name of the function, which should be no different than a variable name. Α sequence of parameters separated by comma surrounded by parantheses.
  202. 202. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . New Functions To define a function we first type the word function. Then, the name of the function, which should be no different than a variable name. Α sequence of parameters separated by comma surrounded by parantheses. Τhe body of the function that is used to map the arguments to a value or values. Typically, the body contains many commands and is surrounded by curly brackets.
  203. 203. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . New Functions To define a function we first type the word function. Then, the name of the function, which should be no different than a variable name. Α sequence of parameters separated by comma surrounded by parantheses. Τhe body of the function that is used to map the arguments to a value or values. Typically, the body contains many commands and is surrounded by curly brackets. Example: function square(number){ return number*number }
  204. 204. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . New Functions cont.
  205. 205. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . New Functions cont. Command return interrupts the execution and forces the function to map the argument to what follows this word.
  206. 206. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . New Functions cont. Command return interrupts the execution and forces the function to map the argument to what follows this word. We can use the function we defined in the previous slide as follows: x = square(3)
  207. 207. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . New Functions cont. Command return interrupts the execution and forces the function to map the argument to what follows this word. We can use the function we defined in the previous slide as follows: x = square(3) Obviously, this command assigns the number 9 to variable x
  208. 208. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . New Functions cont. Command return interrupts the execution and forces the function to map the argument to what follows this word. We can use the function we defined in the previous slide as follows: x = square(3) Obviously, this command assigns the number 9 to variable x Functions in JavaScript can be recursive, that is, they can be defined in terms of themselves.
  209. 209. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . New Functions cont. Command return interrupts the execution and forces the function to map the argument to what follows this word. We can use the function we defined in the previous slide as follows: x = square(3) Obviously, this command assigns the number 9 to variable x Functions in JavaScript can be recursive, that is, they can be defined in terms of themselves. However, I will not discuss them here.
  210. 210. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Event Handling
  211. 211. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Event Handling An event is an action or occurrence that happens in the system one is programming.
  212. 212. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Event Handling An event is an action or occurrence that happens in the system one is programming. A system informs programs about events and so one can program then to respond to them in some way if desired.
  213. 213. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Event Handling An event is an action or occurrence that happens in the system one is programming. A system informs programs about events and so one can program then to respond to them in some way if desired. If a user clicks a button on a web page, a program might respond to that action by displaying an information box.
  214. 214. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Event Handling An event is an action or occurrence that happens in the system one is programming. A system informs programs about events and so one can program then to respond to them in some way if desired. If a user clicks a button on a web page, a program might respond to that action by displaying an information box. In order to define an event handler we need something that will trigger an event.
  215. 215. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Event Handling An event is an action or occurrence that happens in the system one is programming. A system informs programs about events and so one can program then to respond to them in some way if desired. If a user clicks a button on a web page, a program might respond to that action by displaying an information box. In order to define an event handler we need something that will trigger an event. When a user moves the mouse over an area, an event happens.
  216. 216. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Event Handling An event is an action or occurrence that happens in the system one is programming. A system informs programs about events and so one can program then to respond to them in some way if desired. If a user clicks a button on a web page, a program might respond to that action by displaying an information box. In order to define an event handler we need something that will trigger an event. When a user moves the mouse over an area, an event happens. To define an event handler: the name inside a tag followed by an equal sign, followed by JavaScript code that will be invoked when the event associated with the handler happens.
  217. 217. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Event Handling Example
  218. 218. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Event Handling Example <input type="button" value="Calculate" onClick="compute(this.form)">
  219. 219. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Event Handling Example <input type="button" value="Calculate" onClick="compute(this.form)"> When button is clicked, then function compute is called.

×