Java Script The Basics Year 10 Computer Science

Java Script: The Basics Year 10 – Computer Science

Instructions �You need to complete the Power. Point by explaining what the ‘Basics’ are in Java Script. �You will need to understand what each of these mean to successfully complete you first piece of coursework. �You will be tested on the ‘Basics’ in Mondays lesson – print off a completed Power. Point to revise in preparation.

What can Java Script Do? �Java. Script Can Change HTML Content �Java. Script is used on almost every Website for tasks such as form validation, building games, and AJAX requests. But if you’re just getting started as a developer you might not know what all of that really means.

What are the different ways you output in Java Script? � Writing into an alert box, using window. alert(). � Writing into the HTML output using document. write(). � Writing into an HTML element, using inner. HTML. � Writing into the browser console, using console. log(). � Example � <!DOCTYPE html> <body> <h 1>My First Web Page</h 1> <p>My first paragraph. </p> <script> window. alert(5 + 6); </script> </body> </html>

Where do you use Java Script ? � Java. Script is most commonly used as a client side scripting language. This means that Java. Script code is written into an HTML page. When a user requests an HTML page with Java. Script in it, the script is sent to the browser and it's up to the browser to do something with it. Can be used between � <script> � function new 2(icecream 1, icecream 2) �{ � alert("I like eating " + icecream 1+" and "+icecream 2); �} � </script>

What are Statements in Java Script ? �In HTML, Java. Script statements are "instructions" to be "executed" by the web browser. �Example �var x = 5; var y = 6; var z = x + y; document. get. Element. By. Id("demo"). inner. HTML = z;

What are Comments in Java Script? �Java. Script comments can be used to explain Java. Script code, and to make it more readable. �Java. Script comments can also be used to prevent execution, when testing alternative code.

What are Variables in Java Script? �Java. Script variables are containers for storing data values. �In this example, x, y, and z, are variables: �Example �// Change heading: document. get. Element. By. Id("my. H"). inner. HTML = "My First Page"; // Change paragraph: document. get. Element. By. Id("my. P"). inner. HTML = "My first paragraph. ";

What are Operators in Java Script? �Assign values to variables and add them together: �Example �var x = 5; // assign the value 5 to x var y = 2; // assign the value 2 to y var z = x + y; // assign the value 7 to z (x +

What is Concatenation in Java Script? �Use to join two or more things together. �Such as a string and a number.

What are Data Types in Java Script? �In programming, data types is an important concept. �To be able to operate on variables, it is important to know something about the type. �Without data types, a computer cannot safely solve this: �Example �Java. Script variables can hold many data types: numbers, strings, arrays, objects and more: �var length = 16; // Number var last. Name = "Johnson"; // String var cars = ["Saab", "Volvo", "BMW"]; // Array var x = {first. Name: "John", last. Name: "Doe"}; //

What are Objects in Java Script? �In real life, a car is an object. �A car has properties like weight and color, and methods like start and stop: �Example �var person = {first. Name: "John", last. Name: "Doe", age: 50, eye. Color: "blue"};

What are Events in Java Script? �HTML events are "things" that happen to HTML elements. �When Java. Script is used in HTML pages, Java. Script can "react" on these events. �Example �<button onclick='get. Element. By. Id("demo"). inner. HTML=Dat e()'>The time is? </button>

What are Strings in Java Script? �A Java. Script string simply stores a series of characters like "John Doe". �A string can be any text inside quotes. You can use single or double quotes: �Example �var carname = "Volvo XC 60"; var carname = 'Volvo XC 60';

What are Arrays in Java Script? �Java. Script arrays are used to store multiple values in a single variable. �Example �<p id="demo"></p> <script> var cars = ["Saab", "Volvo", "BMW"]; document. get. Element. By. Id("demo"). inner. HTML = cars; </script>

What does Boolean mean in Java Script? �A Java. Script Boolean represents one of two values: true or false. �Example �(10 > 9) // also returns true 10 > 9 // also returns true

What are Conditionals in Java Script? �Conditional statements are used to perform different actions based on different conditions. �Example �Make a "Good day" greeting if the hour is less than 18: 00: �if (hour < 18) { greeting = "Good day"; }

What are Loops in Java Script? �Loops can execute a block of code a number of times. �Example �for (i = 0; i < 5; i++) { text += "The number is " + i + " "; }

What are functions in Java Script? �A Java. Script function is a block of code designed to perform a particular task. �A Java. Script function is executed when "something" invokes it (calls it). �Example �function my. Function(p 1, p 2) { return p 1 * p 2; // The function returns the product of p 1 and p 2 }

What tag must you use before you use Java Script in your code? �<script> �</script>
- Slides: 20