Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

DELHI PUBLIC SCHOOL

SOFT LESSON PLAN - CLASS VI CHAPTER 3


JAVASCRIPT IN HTML DOCUMENT

Introduction

To add functionality to your web page you need a scripting language. JavaScript is one of the most
popular scripting languages of the Internet. It works in all major browsers such as Internet Explorer,
Firefox, Chrome, Opera and Safari. JavaScript is a scripting language with very simple syntax.It is
used to add interactivity to your web pages.

Java Script is:

 JavaScript is a lightweight, interpreted programming language.


 Designed for creating network-centric applications.
 Complementary to and integrated with Java.
 Complementary to and integrated with HTML.
 Open and cross platform.

Writing a JavaScript Program

JavaScript statements can be included in HTML documents by enclosing the statements between
opening and closing<SCRIPT>tag.

The section between opening<SCRIPT> and closing</SCRIPT>tag is called script block. For
example:

<SCRIPT language=”JavaScript”>

…..

[JavaScript statements]

…..

</SCRIPT>

Using External JavaScript File

 Scripts can also be loaded from an external file


 This is useful if you have a complicated script or set of subroutines that are used in several
different documents

For example:

<SCRIPT language=”JavaScript” src=”ScriptFile.js”>

…..
[JavaScript statements]

…..

</SCRIPT>

The Object Model in JavaScript

JavaScript is an object-based language based on prototypes, rather than being class-based. Because of
this different basis, it can be less apparent how JavaScript allows you to create hierarchies of objects
and to have inheritance of properties and their values.

document.write()Method

The document.write() method is used for displaying the text on the browser window. It uses an
object called document, which refers to the content document on the browser.

Writing simple program using JavaScript

<html>

<body>

<script language="javascript">

document.write ("<h1><center><u> Welcome here </h1>");

alert ("This page may contain harmful files.");

alert ("Your computer is at risk.");

document.write ("<center><b>everything is fine, RELAX!!!!");

</script>

</body>

</html>

JavaScript Variables

 JavaScript has variables that you can declare with the optional var keyword
 Variables declared within a function are local to that function
 Variables declared outside of any function are global variables

JavaScript Operators

JavaScript has most of the operators we're used to from C/Java

 Arithmetic (+, - , * , /, %)
 Assignment (= , += , -= , *= /= , %= , ++, --)
 Logical (&&, ||, !)
 Comparison (, <= , >= , ==)

Note: + also does string concatenation

Methods for Window Object

The window object represents an open window in a browser.

If a document contain frames (<iframe> tags), the browser creates one window object for the HTML
document, and one additional window object for each frame.

Method Description Syntax


window.alert() Displays an alert box with a message and an window.alert(message)
OK button
alert (message)
window.confirm() Displays a dialog box with a message and an window.confirm(message)
OK and a Cancel button
alert (message)
window.prompt() Displays a dialog box that prompts the visitor window.prompt(message)
for input
alert (message)

parseInt() and parseFloat() Methods

parseInt() and parseFloat() Methods in Javascript are used to convert to a non-number values into
numbers.parseInt() is for converting a non integer number to an int and parseFloat() is for converting
string until the first decimal point.

Example:

Var x=parseInt(“32.87”) // returns 32

Var y=parseFloat(“14square”) // returns 14.0

Question-Answers

1. What is Javascript?Why is it important?

Ans.JavaScript is a scripting language with a very simple syntax.It is used to add interactivity to
your web page.Javascript is set to execute when you want some changes to be reflected on the
web page.

2. Why document.write() is used?


Ans. The document.write() method is used for displaying the text on the browser window. It uses
an object called document, which refers to the content document on the browser.

3. What is difference between parseInt() and parseFloat()?

Ans. parseInt() and parseFloat() Methods in Javascript are used to convert to a non-number
values into numbers.parseInt() is for converting a non integer number to an int and parseFloat() is
for converting string until the first decimal point.

4. Which operator is known as Concatenation Operator?

Ans. + also does string concatenation.

5. Which browsers are supported by JavaScript?

Ans. JavaScript works in all major browsers such as Internet Explorer, Firefox, Chrome, Opera
and Safari.

*******************************

You might also like