Intro to Programming and Java Script What is

  • Slides: 27
Download presentation
Intro to Programming and Java. Script

Intro to Programming and Java. Script

What is Programming? • Programming is the activity of creating a set of detailed

What is Programming? • Programming is the activity of creating a set of detailed instructions (Program) that when carried out on a consistent set of inputs will result in a consistent set of results. • Programming has been around for several hundred years

History of Programming • 1206 AD – Kurdish medieval scientist built a programmable automata

History of Programming • 1206 AD – Kurdish medieval scientist built a programmable automata – Used pegs and cams in different places that would trigger levers to produce a small drummer playing different rhythms and drum patterns. (Music Box) • 1801 - Jacquard Loom, pasteboard cards with holes punched in them which told the loom the pattern to weave the cloth

History of Programming • 1830 – Charles Babbage adopted punch cards to control his

History of Programming • 1830 – Charles Babbage adopted punch cards to control his Analytical Engine • 1954 – FORTRAN is invented. Allowed user to enter in calculations by a formula directly (Y = X*2 + 5*X + 9) – Used a compiler to translate the text into machine language

History of Programming • Late 1960’s – data storage and computer terminals were cheap

History of Programming • Late 1960’s – data storage and computer terminals were cheap enough that programs could be made directly on computers – Text editors could be used to program (Komodo) • Popular programming languages: Action. Script, C++, C#, Haskell, HTML with PHP, Java. Script, Objective-C, Perl, Python, Ruby, Smalltalk, SQL, Visual Basic, and dozens more.

Programming Lifecycle • Requirements – Documenting the specifications of the problem • Design –

Programming Lifecycle • Requirements – Documenting the specifications of the problem • Design – Creating the Algorithm to solve the problem • Coding – Translating the Algorithm into instructions the computer can understand – Program • Testing – Exercising the Program to ensure the expected results are achieved • Debugging – If the expected results are not achieved; correcting the Algorithm or Program to address the “bugs” • Retesting – Repeating all the testing to ensure the changes solved the problem(s) and didn’t create new problems • Publishing – Making the Program available to the users

STOP • Show programs

STOP • Show programs

Algorithms and Pseudocode • Algorithm – Detailed instructions for solving a problem • Pseudocode

Algorithms and Pseudocode • Algorithm – Detailed instructions for solving a problem • Pseudocode – English like statements mixed with code statements for describing an algorithm

Java. Script • • Used mostly in web browsers Interaction with the user Control

Java. Script • • Used mostly in web browsers Interaction with the user Control Alter content

Some Java. Script Examples • http: //maroslaw. github. io/rainyday. js/demo 1. html • http:

Some Java. Script Examples • http: //maroslaw. github. io/rainyday. js/demo 1. html • http: //www. javascriptfreecode. com/ • https: //cs. mtsu. edu/~mw 3 n/csci 1150. html

First Java. Script Command • document. write(“Stuff goes in here. ”); • Needs to

First Java. Script Command • document. write(“Stuff goes in here. ”); • Needs to go in between <script type=“text/javascript”> document. write(“Stuff goes in here”); </script> • The above needs to go in the body.

First Java. Script Command cont. • All Java. Script commands end with a semicolon

First Java. Script Command cont. • All Java. Script commands end with a semicolon • You can put HTML into the Java. Script command: document. write(“<h 1> HTML from Java. Script </h 1>”);

Finding the Length of Words • document. write(“This sentence has five e’s”. length); •

Finding the Length of Words • document. write(“This sentence has five e’s”. length); • document. write(“Short word”. length); • document. write(“Four”. length)

Java. Script Math! • You can use Java. Script to do Math! document. write(3+4);

Java. Script Math! • You can use Java. Script to do Math! document. write(3+4); document. write(3*4); document. write(3/4); • Can write out a Math equation: document. write(“ 3+4=”, 3+4); • Can multiply numbers with length of words: document. write(“Test”. length*10 );

Java. Script Communication • You can talk to the user! confirm(“Today is a good

Java. Script Communication • You can talk to the user! confirm(“Today is a good day!”); confirm(“I am Batman”); • You can ask for information: prompt(“What is your name? ”); prompt(“What is your quest? ”); prompt(“What is your favorite color? ”);

Java. Script Data Types 1. Numbers: 3, 2. 5, -1000, 2. 888889, etc. You

Java. Script Data Types 1. Numbers: 3, 2. 5, -1000, 2. 888889, etc. You can do math with them! 2. Strings: sequence of characters (words) in quotes “This is a string. ” “Strings can also have numbers like 5 or symbols. ”

Java. Script Data Types cont. • Boolean: only take values true or false •

Java. Script Data Types cont. • Boolean: only take values true or false • Statements can evaluate to true or false • Examples: – 100 > 10 – 8 < 3 – 10. 4 < 30 – “Test”. length < 2

Java. Script Comparisons • • • > : Greater than < : Less than

Java. Script Comparisons • • • > : Greater than < : Less than <= : Less than or equal to >= : Greater than or equal to === : Equal to !== : Not equal to

Practice • Make these true: – document. write(20 10); – document. write(“John Smith”. length

Practice • Make these true: – document. write(20 10); – document. write(“John Smith”. length 100); – document. write(“USA” 3);

Conditionals • Using Comparisons and Conditionals, computers can now make decisions if (100 >

Conditionals • Using Comparisons and Conditionals, computers can now make decisions if (100 > 2) { document. write(“That is correct!”); }

2 Decisions – If, else if (100 > 2) { document. write(“That is correct!”);

2 Decisions – If, else if (100 > 2) { document. write(“That is correct!”); } else { document. write(“That is incorrect. ”); }

If and Else if (100 > 2) { document. write(“That is correct!”); } else

If and Else if (100 > 2) { document. write(“That is correct!”); } else { document. write(“That is incorrect. ”); }

Any Type of Comparison in If/Else if (50/2 === “My Word”. length) { confirm(“Will

Any Type of Comparison in If/Else if (50/2 === “My Word”. length) { confirm(“Will the first block be displayed? ”); } else { confirm(“Or the second block? ”); }

Variables • Variables are like “boxes” or “containers” that can hold data (strings, numbers,

Variables • Variables are like “boxes” or “containers” that can hold data (strings, numbers, booleans) • Declaring some variables: var var var. Name = “String variable”; my. Age = 23; my. Name = “Matt”; my. Bool = true;

Some Variable Rules • Variables can be letters and numbers: – No spaces or

Some Variable Rules • Variables can be letters and numbers: – No spaces or punctuation except underscores – When used, need to be spelled exactly • Variables need to be declared once: var my. Var = “Test variable”; my. Var = “Changing test variable”;

Variables Can Save Data to be Used Later • var test 1 = confirm(“Yes

Variables Can Save Data to be Used Later • var test 1 = confirm(“Yes or no? ”); • var test 2 = prompt(“What is your favorite color? ”); • document. write(“You said: ”, test 1, “ ”); • document. write(“Your favorite color is: ”, test 2, “ ”);

Using Conditionals, Variables, and User Input var my. Age = prompt(“How old are you?

Using Conditionals, Variables, and User Input var my. Age = prompt(“How old are you? ”); if(my. Age >= 18) { document. write(“Welcome to rated R movie. ”); } else { document. write(“You cannot watch the rated R movie. ”); }