Chapter 5 JavaScript in HTML Documents
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>
<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"