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.

JavaScript for pupils

73 views

Published on

An introduction to JavaScript designed for pupils

Published in: Education
  • Be the first to comment

  • Be the first to like this

JavaScript for pupils

  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 (i.e., excessive adherence to prescribed forms) 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 (i.e., excessive adherence to prescribed forms) used to instruct a computer to perform a computational task. Roughly, a computational task solves a computational problem.
  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 (i.e., excessive adherence to prescribed forms) used to instruct a computer to perform a computational task. Roughly, a computational task solves a computational problem. What is computational problem?
  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 (i.e., excessive adherence to prescribed forms) used to instruct a computer to perform a computational task. Roughly, a computational task solves a computational problem. What is computational problem? Answer: A mathematical problem. But what is a mathematical problem?
  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 (i.e., excessive adherence to prescribed forms) used to instruct a computer to perform a computational task. Roughly, a computational task solves a computational problem. What is computational problem? Answer: A mathematical problem. But what is a mathematical problem? Is the Seven Bridges of Königsberg a mathematical problem?
  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 (i.e., excessive adherence to prescribed forms) used to instruct a computer to perform a computational task. Roughly, a computational task solves a computational problem. What is computational problem? Answer: A mathematical problem. But what is a mathematical problem? Is the Seven Bridges of Königsberg a mathematical problem? Are feelings computational processes? Can we download minds?
  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 (i.e., excessive adherence to prescribed forms) used to instruct a computer to perform a computational task. Roughly, a computational task solves a computational problem. What is computational problem? Answer: A mathematical problem. But what is a mathematical problem? Is the Seven Bridges of Königsberg a mathematical problem? Are feelings computational processes? Can we download minds? Back to business: Computers can calculate and enumerate and that’s what we do with programming languages.
  11. 11. 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 (i.e., excessive adherence to prescribed forms) used to instruct a computer to perform a computational task. Roughly, a computational task solves a computational problem. What is computational problem? Answer: A mathematical problem. But what is a mathematical problem? Is the Seven Bridges of Königsberg a mathematical problem? Are feelings computational processes? Can we download minds? 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.
  12. 12. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Characteristics of Programming Languages
  13. 13. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Characteristics of Programming Languages Programming languages are used to describe computational tasks.
  14. 14. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Characteristics of Programming Languages Programming languages are used to describe computational tasks. There are several kinds.
  15. 15. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Characteristics of Programming Languages Programming languages are used to describe computational tasks. There are several kinds. If by a sequence of commands, then it is a imperative one.
  16. 16. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Characteristics of Programming Languages Programming languages are used to describe computational tasks. There are several kinds. If by a sequence of commands, then it is a imperative one. If by objects and their interactions, then it is an object-oriented one.
  17. 17. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Characteristics of Programming Languages Programming languages are used to describe computational tasks. There are several kinds. If by a sequence of commands, then it is a imperative one. If by objects and their interactions, then it is an object-oriented one. If by functions and their composition, then it is a functional one.
  18. 18. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Characteristics of Programming Languages Programming languages are used to describe computational tasks. There are several kinds. If by a sequence of commands, then it is a imperative one. If by objects and their interactions, then it is an object-oriented one. If by functions and their composition, then it is a functional one. If by a set of sentences in logical form, then it is a logic programming one.
  19. 19. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Characteristics of Programming Languages Programming languages are used to describe computational tasks. There are several kinds. If by a sequence of commands, then it is a imperative one. If by objects and their interactions, then it is an object-oriented one. If by functions and their composition, then it is a functional one. If by a set of sentences in logical form, then it is a logic programming one. Specifying a programming language means to: describe its syntax and its semantics.
  20. 20. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Characteristics of Programming Languages Programming languages are used to describe computational tasks. There are several kinds. If by a sequence of commands, then it is a imperative one. If by objects and their interactions, then it is an object-oriented one. If by functions and their composition, then it is a functional one. If by a set of sentences in logical form, then it is a logic programming one. Specifying a programming language means to: describe its syntax and its semantics. Syntax: the way we arrange linguistic elements (commands) in a sentence (a program).
  21. 21. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Characteristics of Programming Languages Programming languages are used to describe computational tasks. There are several kinds. If by a sequence of commands, then it is a imperative one. If by objects and their interactions, then it is an object-oriented one. If by functions and their composition, then it is a functional one. If by a set of sentences in logical form, then it is a logic programming one. Specifying a programming language means to: describe its syntax and its semantics. Syntax: the way we arrange linguistic elements (commands) in a sentence (a program). Semantics: what is the meaning (computational effect) of each linguistic element (command).
  22. 22. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Some popular programming languages
  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:
  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,
  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,
  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,
  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,
  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,
  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,
  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.
  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:
  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,
  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++,
  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,
  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,
  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.
  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:
  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,
  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,
  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,
  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,
  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,
  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#,
  44. 44. 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.
  45. 45. 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.
  46. 46. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is Programming?
  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.
  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.
  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. The solution is called an algorithm.
  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. The solution is called an algorithm. Programming is not something you learn by following a recipe or a method.
  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. The solution is called an algorithm. Programming is not something you learn by following a recipe or a method. Programming is both a craft and a science.
  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. The solution is called an algorithm. 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 several rules of thumb that one can follow to solve a problem.
  53. 53. 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. The solution is called an algorithm. 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 several rules of thumb that one can follow to solve a problem. However, intuition plays a very important when solving a problem.
  54. 54. 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. The solution is called an algorithm. 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 several rules of thumb that one can follow to solve a problem. However, intuition plays a very important when solving a problem. A programmer is a scientist if mathematicians are scientists.
  55. 55. 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. The solution is called an algorithm. 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 several rules of thumb that one can follow to solve a problem. However, intuition plays a very important when solving a problem. A programmer is a scientist if mathematicians are scientists. The realization of a solution requires the knowledge of common techniques and practicers.
  56. 56. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Steps Involved in Programming
  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.
  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.
  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.
  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.
  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.
  62. 62. 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.
  63. 63. 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.
  64. 64. 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.
  65. 65. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is JavaScript?
  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.
  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.
  68. 68. 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 the <script> element.
  69. 69. 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 the <script> element. JavaScript can be used to make dynamic web pages.
  70. 70. 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 the <script> element. JavaScript can be used to make dynamic web pages. JavaScript and Java are object-oriented languages and this is their only similarity.
  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
  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:
  73. 73. 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>
  74. 74. 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
  75. 75. 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> …
  76. 76. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A Complete Example
  77. 77. 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:
  78. 78. 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>
  79. 79. 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.
  80. 80. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Testing What We Will Learn
  81. 81. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Testing What We Will Learn To test things please replace the JavaScript code with your code in the following input file.
  82. 82. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Testing What We Will Learn To test things please replace the JavaScript code with your code in the following input file. <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Example</title> </head><body> <script> var x=5 x += 2 document.writeln(x) </script> </body> </html>
  83. 83. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Testing What We Will Learn To test things please replace the JavaScript code with your code in the following input file. <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Example</title> </head><body> <script> var x=5 x += 2 document.writeln(x) </script> </body> </html> Open your text-editor, type the code, save the file and open it with your browser.
  84. 84. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Values A value can be…
  85. 85. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Values A value can be… A number, that is, a quantity like 41 or 3.14159.
  86. 86. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Values A value can be… A number, that is, a quantity like 41 or 3.14159. A Boolean (logical) value, that is, either the value true or the value false. These values are answers to questions like 3 ≠ 4 or 3 < 4.
  87. 87. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Values A value can be… A number, that is, a quantity like 41 or 3.14159. A Boolean (logical) value, that is, either the value true or the value false. These values are answers to questions like 3 ≠ 4 or 3 < 4. A sequence of characters enclosed in quotation marks that are known as strings.
  88. 88. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Values A value can be… A number, that is, a quantity like 41 or 3.14159. A Boolean (logical) value, that is, either the value true or the value false. These values are answers to questions like 3 ≠ 4 or 3 < 4. A sequence of characters enclosed in quotation marks that are known as strings. NB. A string must be enclosed in either single or double quotation marks: "John's girlfriend." or 'Mary came!'.
  89. 89. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Values A value can be… A number, that is, a quantity like 41 or 3.14159. A Boolean (logical) value, that is, either the value true or the value false. These values are answers to questions like 3 ≠ 4 or 3 < 4. A sequence of characters enclosed in quotation marks that are known as strings. NB. A string must be enclosed in either single or double quotation marks: "John's girlfriend." or 'Mary came!'. The literal null, which denotes a no value.
  90. 90. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Values A value can be… A number, that is, a quantity like 41 or 3.14159. A Boolean (logical) value, that is, either the value true or the value false. These values are answers to questions like 3 ≠ 4 or 3 < 4. A sequence of characters enclosed in quotation marks that are known as strings. NB. A string must be enclosed in either single or double quotation marks: "John's girlfriend." or 'Mary came!'. The literal null, which denotes a no value. The literal undefined, which denotes an undefined value.
  91. 91. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Variables
  92. 92. 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.
  93. 93. 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 ….
  94. 94. 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.
  95. 95. 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. As time passes a variable may designate a different value.
  96. 96. 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. As time passes a variable may designate a different value. Think of a process that counts objects. A variable standing for the current number of objects will have different values at different moments.
  97. 97. 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. As time passes a variable may designate a different value. Think of a process that counts objects. A variable standing for the current number of objects will have different values at different moments. The first character of the name of a variable must be a letter
  98. 98. 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. As time passes a variable may designate a different value. Think of a process that counts objects. A variable standing for the current number of objects will have different values at different moments. 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).
  99. 99. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using Variables
  100. 100. 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.
  101. 101. 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.
  102. 102. 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.
  103. 103. 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.
  104. 104. 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.
  105. 105. 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.
  106. 106. 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 // + denotes addition
  107. 107. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons
  108. 108. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons 𝐴 ⊜ 𝐵, where ⊜ is a comparison operator.
  109. 109. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons 𝐴 ⊜ 𝐵, where ⊜ is a comparison operator. The standard comparison operators are:
  110. 110. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons 𝐴 ⊜ 𝐵, where ⊜ is a comparison operator. The standard comparison operators are: == (equal to),
  111. 111. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons 𝐴 ⊜ 𝐵, where ⊜ is a comparison operator. The standard comparison operators are: == (equal to), != (not equal to),
  112. 112. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons 𝐴 ⊜ 𝐵, where ⊜ is a comparison operator. The standard comparison operators are: == (equal to), != (not equal to), < (less than),
  113. 113. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons 𝐴 ⊜ 𝐵, where ⊜ is a comparison operator. The standard comparison operators are: == (equal to), != (not equal to), < (less than), > (greater than),
  114. 114. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons 𝐴 ⊜ 𝐵, 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
  115. 115. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons 𝐴 ⊜ 𝐵, 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).
  116. 116. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons 𝐴 ⊜ 𝐵, 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,
  117. 117. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons 𝐴 ⊜ 𝐵, 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;
  118. 118. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons 𝐴 ⊜ 𝐵, 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;
  119. 119. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons 𝐴 ⊜ 𝐵, 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 false;
  120. 120. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons 𝐴 ⊜ 𝐵, 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 false; y == underfined evaluates to true;
  121. 121. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparisons 𝐴 ⊜ 𝐵, 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 false; y == underfined evaluates to true; x <= 5 evaluates to true.
  122. 122. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arrays
  123. 123. 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 any moment.
  124. 124. 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 any moment. Each value is assigned to an element of an array and one can refer to an array by its index, which is a natural number (i.e., 0, 1, 2, etc.).
  125. 125. 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 any moment. Each value is assigned to an element of an array and one can refer to an array by its index, which is a natural number (i.e., 0, 1, 2, etc.).
  126. 126. 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 any moment. Each value is assigned to an element of an array and one can refer to an array by its index, which is a natural number (i.e., 0, 1, 2, etc.). 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"]
  127. 127. 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 any moment. Each value is assigned to an element of an array and one can refer to an array by its index, which is a natural number (i.e., 0, 1, 2, etc.). 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])
  128. 128. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Strings Strings consist of simple ASCII characters (i.e., the basic Latin letters), escape sequences, or Unicode characters (i.e., any symbol from most writing systems).
  129. 129. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Strings Strings consist of simple ASCII characters (i.e., the basic Latin letters), escape sequences, or Unicode characters (i.e., any symbol from most writing systems). An escape sequence corresponds to a special character that cannot be entered conventionally (e.g., the ESC key or the new line character).
  130. 130. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Strings Strings consist of simple ASCII characters (i.e., the basic Latin letters), escape sequences, or Unicode characters (i.e., any symbol from most writing systems). An escape sequence corresponds to a special character that cannot be entered conventionally (e.g., the ESC key or the new line character). Escape sequences consist of a backslash followed by a single letter.
  131. 131. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Strings Strings consist of simple ASCII characters (i.e., the basic Latin letters), escape sequences, or Unicode characters (i.e., any symbol from most writing systems). An escape sequence corresponds to a special character that cannot be entered conventionally (e.g., the ESC key or the new line character). Escape sequences consist of a backslash followed by a single letter. The character n) “prints” a new new line character.
  132. 132. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators
  133. 133. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators 𝐴 ⊕ 𝐵, where ⊕ is an arithmetic operator.
  134. 134. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators 𝐴 ⊕ 𝐵, where ⊕ is an arithmetic operator. The standard arithmetic operators are:
  135. 135. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators 𝐴 ⊕ 𝐵, where ⊕ is an arithmetic operator. The standard arithmetic operators are: + (plus, denotes addition),
  136. 136. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators 𝐴 ⊕ 𝐵, where ⊕ is an arithmetic operator. The standard arithmetic operators are: + (plus, denotes addition), - (minus, denotes subtraction),
  137. 137. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators 𝐴 ⊕ 𝐵, where ⊕ is an arithmetic operator. The standard arithmetic operators are: + (plus, denotes addition), - (minus, denotes subtraction), * (times, denotes multiplication),
  138. 138. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators 𝐴 ⊕ 𝐵, where ⊕ is an arithmetic operator. The standard arithmetic operators are: + (plus, denotes addition), - (minus, denotes subtraction), * (times, denotes multiplication), / [the equivalent of obelus (÷) used for division],
  139. 139. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators 𝐴 ⊕ 𝐵, where ⊕ is an arithmetic operator. The standard arithmetic operators are: + (plus, denotes addition), - (minus, denotes subtraction), * (times, denotes multiplication), / [the equivalent of obelus (÷) used for division], % (remainder of integer division), and
  140. 140. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators 𝐴 ⊕ 𝐵, where ⊕ is an arithmetic operator. The standard arithmetic operators are: + (plus, denotes addition), - (minus, denotes subtraction), * (times, denotes multiplication), / [the equivalent of obelus (÷) used for division], % (remainder of integer division), and ** (exponentiation, that is, x**y stands for 𝑥 𝑦 ).
  141. 141. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators 𝐴 ⊕ 𝐵, where ⊕ is an arithmetic operator. The standard arithmetic operators are: + (plus, denotes addition), - (minus, denotes subtraction), * (times, denotes multiplication), / [the equivalent of obelus (÷) used for division], % (remainder of integer division), and ** (exponentiation, that is, x**y stands for 𝑥 𝑦 ). Suppose that x = 5 and y=4 were just executed. Then,
  142. 142. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators 𝐴 ⊕ 𝐵, where ⊕ is an arithmetic operator. The standard arithmetic operators are: + (plus, denotes addition), - (minus, denotes subtraction), * (times, denotes multiplication), / [the equivalent of obelus (÷) used for division], % (remainder of integer division), and ** (exponentiation, that is, x**y stands for 𝑥 𝑦 ). Suppose that x = 5 and y=4 were just executed. Then, x+y evaluates to 9;
  143. 143. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators 𝐴 ⊕ 𝐵, where ⊕ is an arithmetic operator. The standard arithmetic operators are: + (plus, denotes addition), - (minus, denotes subtraction), * (times, denotes multiplication), / [the equivalent of obelus (÷) used for division], % (remainder of integer division), and ** (exponentiation, that is, x**y stands for 𝑥 𝑦 ). Suppose that x = 5 and y=4 were just executed. Then, x+y evaluates to 9; x-y evaluates to 1;
  144. 144. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators 𝐴 ⊕ 𝐵, where ⊕ is an arithmetic operator. The standard arithmetic operators are: + (plus, denotes addition), - (minus, denotes subtraction), * (times, denotes multiplication), / [the equivalent of obelus (÷) used for division], % (remainder of integer division), and ** (exponentiation, that is, x**y stands for 𝑥 𝑦 ). Suppose that x = 5 and y=4 were just executed. Then, x+y evaluates to 9; x-y evaluates to 1; x*y evaluates to 20;
  145. 145. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators 𝐴 ⊕ 𝐵, where ⊕ is an arithmetic operator. The standard arithmetic operators are: + (plus, denotes addition), - (minus, denotes subtraction), * (times, denotes multiplication), / [the equivalent of obelus (÷) used for division], % (remainder of integer division), and ** (exponentiation, that is, x**y stands for 𝑥 𝑦 ). Suppose that x = 5 and y=4 were just executed. Then, x+y evaluates to 9; x-y evaluates to 1; x*y evaluates to 20; x/y evaluates to 1.25;
  146. 146. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators 𝐴 ⊕ 𝐵, where ⊕ is an arithmetic operator. The standard arithmetic operators are: + (plus, denotes addition), - (minus, denotes subtraction), * (times, denotes multiplication), / [the equivalent of obelus (÷) used for division], % (remainder of integer division), and ** (exponentiation, that is, x**y stands for 𝑥 𝑦 ). Suppose that x = 5 and y=4 were just executed. Then, x+y evaluates to 9; x-y evaluates to 1; x*y evaluates to 20; x/y evaluates to 1.25; x%y evaluates to 1;
  147. 147. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operators 𝐴 ⊕ 𝐵, where ⊕ is an arithmetic operator. The standard arithmetic operators are: + (plus, denotes addition), - (minus, denotes subtraction), * (times, denotes multiplication), / [the equivalent of obelus (÷) used for division], % (remainder of integer division), and ** (exponentiation, that is, x**y stands for 𝑥 𝑦 ). Suppose that x = 5 and y=4 were just executed. Then, x+y evaluates to 9; x-y evaluates to 1; x*y evaluates to 20; x/y evaluates to 1.25; x%y evaluates to 1; x**y evaluates to 625.
  148. 148. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Assignment Operators
  149. 149. 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.
  150. 150. 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:
  151. 151. 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.
  152. 152. 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;
  153. 153. 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;
  154. 154. 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
  155. 155. 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.
  156. 156. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . More Arithmetic Operators
  157. 157. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . More Arithmetic Operators x++
  158. 158. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . More Arithmetic Operators x++ Yields the value of x and then increases the value of x by one.
  159. 159. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . More Arithmetic Operators x++ Yields the value of x and then increases the value of x by one. x--
  160. 160. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . More Arithmetic Operators 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.
  161. 161. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . More Arithmetic Operators 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
  162. 162. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . More Arithmetic Operators 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.
  163. 163. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . More Arithmetic Operators 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
  164. 164. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . More Arithmetic Operators 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.
  165. 165. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . More Arithmetic Operators 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
  166. 166. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . More Arithmetic Operators 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.
  167. 167. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Boolean Operators
  168. 168. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Boolean Operators x && y
  169. 169. 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.
  170. 170. 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
  171. 171. 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.
  172. 172. 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
  173. 173. 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.
  174. 174. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . About Commands in General
  175. 175. 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.
  176. 176. 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.
  177. 177. 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:
  178. 178. 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.
  179. 179. 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.
  180. 180. 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.
  181. 181. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The if command
  182. 182. 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)
  183. 183. 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!") }
  184. 184. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The switch Command
  185. 185. 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; }
  186. 186. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The for Command
  187. 187. 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 }
  188. 188. 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
  189. 189. 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>")
  190. 190. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The do-while Command
  191. 191. 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)
  192. 192. 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
  193. 193. 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);
  194. 194. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The while Command
  195. 195. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The while Command while (condition){ commands }
  196. 196. 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
  197. 197. 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++; };
  198. 198. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Labels
  199. 199. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Labels label: command
  200. 200. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Labels label: command Example
  201. 201. 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);
  202. 202. 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); Note that numbers can be automatically transformed into strings.
  203. 203. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The break command
  204. 204. 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
  205. 205. 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
  206. 206. 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; } }
  207. 207. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The continue command
  208. 208. 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
  209. 209. 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
  210. 210. 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 }
  211. 211. Introduction to JavaScript Syropoulos Programming Languages Basics of JavaScript Expressions and Operators Basic Commands Defining New Functions Finale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is a Function?
  212. 212. 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.).
  213. 213. 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.
  214. 214. 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 𝐵.

×