CSSL Soln
CSSL Soln
what is your Browser Application name?
«
scrip
document getElementById("p1").innerHTML =
“Browser Application name is: " + navigator.appName;
document getElementById("p2").innerHTML =
"Browser Application code name isi *
" + navigator.appCodeName:
document getElementById("p2").innerHTML =
“Browser version is: " + navigator.appVersion;
Q.1(d) Write a JavaScript that initializes an array called “Fruits” with names of five (2]
fruits. The script then displays the array in a message box.
Ans.
The length property returns the length of an array.
htm
Q.1(e) Give syntax of and explain the use of “with” statement/clause in JavaScript using [2]
suitable example.
‘Ans.: The ‘with’ statement adds the given object to the head of this scope chain during the
evaluation of its statement body. If an unqualified name used in the body matches a
property in the scope chain, then the name is bound to the property and the object
containing the property. Otherwise a ReferenceError is thrown,
Syntax:
with (expression)
statement
Example:
function f(foo, values)
{
with (foo)
{
document.write(values);
)
}
Q.1(F) Enlist and explain the use of any two Intrinsic JavaScript functions. ica)
Ans.: abs()
Returns the absolute value of a number.
exp)
Returns EN, where N is the argument, and E is Euler's constant, the base of the natural
logarithm.
Q.1(g) State and explain what is a session cookie ? 2
‘Ans.i © A session cookie contains information that is stored ina temporary memory — location
and then subsequently deleted after the session is completed or the web browser is
closed. This cookie stores information that the user has inputted and tracks the
movements of the user within the website.
+ The main difference between a session and a cookie is that session data is stored on the
server, whereas cookies store data in the visitor's browser. Sessions are more secure
than cookies as it is stored in server
Q.2__ Attempt any THREE of the following fz}
Q.2(a) What are javaScript Accessors (setters and getters)? 4]
Ans.: © Getters and setters exist in most object-oriented programming languages, including
JavaScript.
+ They are code constructs that help developers access the properties of objects in a
secure way.
+ With getters, you can access ("get") the values of properties from external code, while
setters let you change ("set") their values
+ Itgives simpler syntax.
+ Ttallows equal syntax for properties and methods.
+ Itcan secure better data quality
* A TavaScript object can have multiple properties and methods that store static data
‘and dynamic functionality. Properties are static key-value pairs, while metheds are
functions specific to the objectPrelim Question Paper Solution
+ For example, Car.color could be a property, while Car.drive() could be a method of
the Carobject. With a getter, you can access the color property of the Car object and
with a setter, you can modify its value (for instance, from blue to black),
+ To get the properties of the Car object, you need to call the getter methods.
Example:
var obj = {
Ex: ‘this is the value of foo",
get€x: function()
(
return this.Ex;
)
setEx: function(val)
{
this.Ex = val;
)
)
console.log(obj.getEx()):
// "this is the value of
obj setEx(‘hello’):
foo"
console.log(obj.getEx()):
17 “hello”
Q.2(b) Write a JavaScript program which compute, the average marks of the following [4]
students Then, this average is used to determine the corresponding grade.
Ans.:
student Name ‘Marks
‘Advait 80
‘Anay 77
‘Manyata 88
‘Saanvi 95
‘Saachi 68
Ranae | Grade
<60
«70
<80
<90)
<100)
This is new Windows/p>");
}
function moveWin() {
myWindow.moveTo(500, 100);
myWindow.Focus():
)
Prelim Question Paper Solution