[Go to site: main page, start]

0% found this document useful (0 votes)
12 views2 pages

Chapter 5 JavaScript in HTML Documents

Chapter 5 discusses the integration of JavaScript within HTML documents, covering its syntax, methods like document.write(), and user interaction through dialog boxes. It highlights the benefits of JavaScript for adding interactivity to web pages and its compatibility with major browsers. The chapter also explains variable declaration and various types of operators used in JavaScript.

Uploaded by

alleharshika
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Chapter 5 JavaScript in HTML Documents

Chapter 5 discusses the integration of JavaScript within HTML documents, covering its syntax, methods like document.write(), and user interaction through dialog boxes. It highlights the benefits of JavaScript for adding interactivity to web pages and its compatibility with major browsers. The chapter also explains variable declaration and various types of operators used in JavaScript.

Uploaded by

alleharshika
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Chapter 5 – JavaScript in HTML Documents

A.
1. False
2. True
3. True
4. True
5. True

B.
<HTML>
<HEAD>
<BODY>
<SCRIPT language="JavaScript">
var str1, str2
str1 = "Click"
str2 = "Start"
[Link](str1 + str2 + " </Br>"); // to add a space in between
[Link](str1 + " " + str2);
</SCRIPT>
</BODY>
</HEAD>
</HTML>

Single line comments:


// This is comment line 1

Multiple line comments:


/* This is comment line 1
This is comment line 2 */

var length, breadth, height, volume

<HTML>
<BODY>
<SCRIPT language="JavaScript">
var reply = confirm("Plant more trees")
[Link](reply);
</SCRIPT>
</BODY>
</HTML>

C.
1. The [Link]() method is used for displaying text on the browser window. It uses an object called
document, which refers to the current document on the browser window.
2. The prompt dialog box is also a method of the window object. It is used for getting input from the user. It
displays an Explorer User Prompt dialog box with a message and an input field.
3. [Link]() is a method of the window object. It is the simplest dialog box used to display a short message to
the user in a separate small window. The dialog box contains the text given as a parameter to the alert() method
and a button labelled OK.
4. This method returns true if OK is pressed and false if Cancel is pressed.
5. parseInt() method converts a string value into integers (numbers without decimal places).
6. parseFloat() method converts a string value into floating numbers (numbers with decimal values).

D.
1. JavaScript is a scripting language with a very simple syntax. It is used to add interactivity to your web pages.
JavaScript is set to execute when you want some change to be reflected on the web page, such as when a page
has finished loading or when a user clicks on an HTML element.
This type of interaction requires knowledge of constructs such as IF statements and FOR loops which are not part
of the HTML syntax.
JavaScript is used because:
a. It helps to add interactive elements to the HTML pages.
b. It is a scripting language which is also a lightweight programming language.
c. Everyone can use JavaScript without using a licence.
d. It is supported by all major browsers, such as Internet Explorer, Firefox, Chrome, Opera and Safari.
e. A JavaScript is lines of executable computer code usually embedded directly in HTML pages.
2. Like most other programming languages of its generation, JavaScript is also characterised by the Object Model.
3. HTML tags can also be included in the JavaScript code to generate HTML elements that will be displayed in the
browser window.
4. You can declare a variable in JavaScript by using var along with the variable name.
var n1, result
var fname
var age
var n1 = 2
var fname = "Avika"

Various types of operators in JavaScript are discussed below:


a. Arithmetic operators: These operators are used to perform arithmetic calculations using variables or constants.
b. Comparison operators: These operators are used to test if two variables relate to each other in the specified
way.
c. Logical operators: These operators perform logical operations on variables.
d. String operator: A string is a set of characters. To join two or more string values together, you use the plus (+)
operator. This is also known as the string concatenation operator.

You might also like