You are on page 1of 8

Java Script

1st Term Project

Done by: Jalal Nimer


JavaScript Tutorial
JavaScript is one of the 3 languages all web
developers must learn:

• 1. HTML to define the content of web pages

• 2. CSS to specify the layout of web pages

• 3. JavaScript to program the behavior of web pages


• JavaScript code is inserted between <script> and
</script> tags.
Old JavaScript examples may use a type attribute:
<script
type="text/javascript">.
JavaScript in <head> or <body>

• JavaScript code is inserted • You can place any number


between <script> and of scripts in an HTML
</script> tags. document.

Old JavaScript examples may • Scripts can be placed in the


use a type attribute: <script <body>, or in the <head>
type="text/javascript">. section of an HTML page,
or in both.
JavaScript (Head and Body)
• Writing into the HTML output using
• document.write()

• For testing purposes, it is convenient to


• use document.write():
• Example:

<html>
<body>
<h1>My First Web Page</h1>
<p>My first paragraph.</p>
<script>
document.write(5 + 6);
</script>
</body>
</html>
Output
• Writing into the HTML • Example:
output using
• document.write() <html>
<body>
• For testing purposes, it is <h1>My First Web Page</h1>
convenient to <p>My first paragraph.</p>
• use document.write(): <script>
document.write(5 + 6);
</script>
</body>
</html>
Pop Up Boxes
• Using alert() Confirm (Process confirmation?);

• You can use an alert box to display data:Confirm </script>


Box
A confirm box is often used if you want the user to </body>
verify or accept something.
• When a confirm box pops up, the user will have
to click either "OK" or "Cancel" to proceed. </html>

• Example: Example:
<html> <html>
<body> <body>
<script> <h1>My First Web Page</h1>
Confirm (Process confirmation?); <p>My first paragraph.</p>
</script> <script>
</body> alert (5 + 6);
</html> </script>
</body>
</html>
Booleans
• A JavaScript Boolean represents one of two values: true or false.

Boolean Values

Very often, in programming, you will need a data type that can only
have one of two values, like

YES / NO
ON / OFF
TRUE / FALSE
For this, JavaScript has a Boolean data type. It can only take the values
true or false.

You might also like