Lesson3 Excecise Solution1

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

Class :-12th Science Information Technology Teacher : Mrs.

Shilpa Kate

Exercise solution : Lesson No.3. Advanced JavaScript

Q.1 Fill in the BLANKS.


1. Server side script resides on server computer.
2. BREAK STATEMent is used to jump out of loop.
3. DOM (Document Object Model) defines LOGICAL structure of document.

4. The closed property returns a Boolean value indicating whether a window has been
closed or not.
5. Onblur event occurs when AN element looses its focus.

Q.2. STATE whether given STATEMENT is true or FALSE.


1. JAVASCRIPT is CASE sensitive LANGUAGE.
ANS: TRUE
2. MAX_VALUE property of number object returns SMALLEST possible
VALUE.

ANS: FALSE
3. GETDAY() method of DATE object returns month in number.
ANS: FALSE
4. onKeydown event occurs when user moves mouse pointer.
ANS: FALSE

Q.3. Multiple choice questions. Select one correct ANSWER.


1. JAVASCRIPT is ---------------------- LANGUAGE.
a) Compiled
b) Interpreted
c) Both A AND b
d) None of the ABOVE
2. Select correct method NAME of String object --.
a) CHARAT() b) CHARACTERAT()
c) VALUEAT() d) lengthAt()
3. ---------------- method DISPLAYS MESSAGE box with Ok AND CANCEL
button.
A) Confirm() b) Alert()
c) both A AND b d) None of these
4. We CAN DECLARE ALL types of VARIABLES using keyword --.
a) VAR b) dim
c) VARIABLE d) DECLARE
5. TRACE ouput of following JAVASCRIPT code.
VAR STR="INFORMATION Technology";

document.write(str. LASTINDEXOF("O"); A) 18 b) 19
c) 20 d) 21

Q.4. Multiple choice questions. Select two correct ANSWER.


1. VALID two methods of DATE object ARE ---------------- AND --.
a) setTime()
` b) GETVALIDTIMe()
c) getTime()
d) SETVALIDTIMe()
2. Properties of document object ARE---------------- AND --.

a) URL b) title
c) NAME D)STATUS

3. ---------- AND ----------- ARE event HANDLER used with text object
in JAVASCRIPT.
A) onBlur b) onMove
e) onFocus d) onAction

Q.5 Multiple choice questions. Select three correct ANSWERS.


1. Select three correct methods of window object----------------
a) write() b) ALERT()
c) writeln() d) close()
e) open() f) CHARAT()
2. JAVASCRIPT FEATURES ARE ----------------------- , ---------------AND -----------------.
a) supports event BASED FACILITIES
b) is PLATFORM dependent LANGUAGE
c) CASE insensitive scripting LANGUAGE
d) provide inbuilt objects
e) CAN HANDLE dATE AND time effectively
f) requires SPECIAL SOFTWARE to run
3. Inbuilt objects in JAVASCRIPT ARE-----------------, AND-------------.

a) Time b) DATE
c) INHERITANCE d) ARRAY
e) Number f) function
Q.6 ExplAIN the following.
1. WHAT ARE similARITIES AND differences between client side scripting
AND server side scripting.

2. Briefly EXPLAIN FEATURES of JAVASCRIPT.


Ans:- Features of JavaScript
a. JavaScript is light weight scripting language because it does not support all
features
of object oriented programming languages No need of special software to run
JavaScript programs
b. JavaScript is object oriented scripting language and it supports event based programming
facility. It is case sensitive language.
c. JavaScript helps the browser to perform input validation without wasting the
user's time by the Web server access.
d. It can handle date and time very effectively.
e. Most of the JavaScript control statements syntax is same as syntax of control
statements in other programming languages.
f. An important part of JavaScript is the ability to create new functions within scripts.
Declare a function in JavaScript using function keyword.
g. Software that can run on any hardware platform (PC, Mac, SunSparc etc.) or software
platform (Windows, Linux, Mac OS etc.) is called as platform independent software.
JavaScript is known as universal client side scripting language.

3. EXPLAIN switch........... CASE CONDITIONAL STATEMENT in JAVASCRIPT with EXAMPLE.


Ans: Switch Case statement
• JavaScript has a built–in multiway decision statement known as Switch. The switch
statement test the value of given expression against a list of case values and when
match is found, a block of statement associated with that case is executed.
• There should not be duplicity between the cases.
• The value for the case must be similar data type as the variable in switch.
• The default statement is not mandatory.

Q.7 Write event driven JAVASCRIPT PROGRAM for the following.


1. DISPLAY Addition, MULTIPLICATION, division AND REMAINDER of two
numbers, which were ACCEPTED from user.
<!doctype html>

<html>

<head><title>Calculator using Javascript</title>

<script type="text/javascript">

var result=0;

function calc()

var n1=parseInt(f1.t1.value);

var n2=parseInt(f1.t2.value);

document.write("<br>Accepted Numbers are n1= "+n1+" & n2="+n2);

result=n1+n2;

document.write("<br>Addition is="+result);

result=n1*n2;

document.write("<br>Multiplication is="+result);

result=n1/n2;

document.write("<br>division ans is="+result);

result=n1%n2;

document.write("<br>Reminder is="+result);

</script>

</head>

<body>

<form name="f1">

Enter first Number:<input type="text" name="t1"><br><br>

Enter Second Number:<input type="text" name="t2"><br><br>


<input type="button" value="Calculator" onClick="calc()">

</form>

</body>

</html>

2. DISPLAY number sequence from 100 to 150 in following FORMAT.


(100 101 102.............150)

//2.DISPLAY number sequence from 100 to 150 in following


FORMAT.
// 100 101 102 103....150
<!Doctype html>
<HTML>
<Head><title>Display numbers</title>
<script type="text/javascript">
function dis()
{
var i=1
for(i=100;i<=150;i++)
{
document.write(i+" ");
}
}
</script>
</Head>
<body>
<form name="f1">
<input type="button" value="display Numbers" onClick="dis()">
</form>
</body>
</HTML>

3. Find AND DISPLAY FACTORIAL of given number.


Ans: //Find AND DISPLAY FACTORIAL of given number
<!Doctype html>

<HTML>

<Head><title>Factorial of given number</title>

<script type="text/javascript">

function fact()

i=1,fact=1;

var num=parseInt(f1.t1.value); //To accept value

for(i=1;i<=num;i++)

fact=fact*i;

document.write("factorial of "+num+"="+fact);

</script>

</Head>

<body>
<form name="f1">

Enter number:<input type="text" name="t1">

<input type="button" value="find factorial" onClick="fact()">

</form>

</body>

</HTML>

4. Accept ANY string from user AND count AND DISPLAY number of
vowels occurs in it.
Ans:
<html>
<head>
<title>find number of vowels in a string in JavaScript</title>
<script type="text/javascript">
function Vowels()
{
var str = document.getElementById("t1").value;
var count = 0, total_vowels="";
for (var i = 0; i < str.length; i++)
{
// findVowels
if(str.charAt(i)=="a"||str.charAt(i)=="e"||str.charAt(i)=="i"||str.charAt(i)=="o"||str.ch
arAt(i)=="u"||str.charAt(i)=="A"||str.charAt(i)=="E"||str.charAt(i)=="I"||str.charAt(i)
=="O"||str.charAt(i)=="U")
{
count++;
}
}

alert("VOWEL count is="+ count);


}
</script>
</head>
<body>
<form>
<h1>Get Vowels from String</h1>
Enter Text :<input type="text" id="t1" />
<input type="button" value="Get Vowels Count" onclick="Vowels()" />
</form>
</body>
</html>

You might also like