document.write("Hello World!") script use a function called document.write, which writes a string into our HTML document."> document.write("Hello World!") script use a function called document.write, which writes a string into our HTML document.">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lect2 (MCS/BCS) Javascript.

Similar presentations


Presentation on theme: "Lect2 (MCS/BCS) Javascript."— Presentation transcript:

1 Lect2 (MCS/BCS) Javascript

2 HTML & JavaScript Code:
<html> <body> <script type="text/JavaScript"> document.write("Hello World!") </script> </body> </html> script use a function called document.write, which writes a string into our HTML document.

3 File myjs.js Contents: function popup() { alert("Hello World") }

4 HTML & JavaScript Code:
<html> <head> <script src="myjs.js"> </script> </head> <body> <input type="button" onclick="popup()" value="Click Me!"> </body> </html>

5 javascript arithmetic operator chart
Addition Subtraction Multiplication Division Reminder

6 javascript operator example with variables
<body> <script type="text/JavaScript"> var two = 2 var ten = 10 var linebreak = "<br />" document.write("two plus ten = ") var result = two + ten document.write(result) document.write(linebreak) document.write("ten * ten = ") result = ten * ten document.write("ten / two = ") result = ten / two </script> </body>

7 comparison operators == < > <= >= etc

8 javascript using variables
A variable's purpose is to store information so that it can be used later. A variable is a symbolic name that represents some data that you set.

9 HTML & JavaScript Code:
<body> <script > var linebreak = "<br />" var my_var = "Hello World!" document.write(my_var) document.write(linebreak) my_var = "I am learning JavaScript!" my_var = "Script is Finishing up..." </script> </body>

10 Output Hello World! I am learning JavaScript! Script is Finishing up...

11 what's a function? A function is a piece of code that sits hidden until it is referenced or called upon to do its "function". In addition to controllable execution, functions are also a great time saver for doing repetitive tasks.

12 example function in javascript
A function that does not execute when a page loads should be placed inside the head of your HTML document. Creating a function is really quite easy. All you have to do is tell the browser you're making a function, give the function a name, and then write the JavaScript like normal. Example

13 HTML & JavaScript Code:
<html> <head> <script type="text/javascript"> function popup() { alert("Hello World") } </script> </head> <body> <input type="button" onclick="popup()" value="popup"> </body> </html>

14 events in javascript <html> <head> <script type="text/javascript"> <!-- function popup() { alert("Hello World") } //--> </script> </head> <body> <input type="button" value="Click Me!" onclick="popup()"><br /> <a href="#" onmouseover="" onMouseout="popup()"> Hover Me!</a> </body> </html>


Download ppt "Lect2 (MCS/BCS) Javascript."

Similar presentations


Ads by Google