0% found this document useful (0 votes)
19 views22 pages

CSS Ut1 Answers

sfdsgd

Uploaded by

Ritu Patil
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)
19 views22 pages

CSS Ut1 Answers

sfdsgd

Uploaded by

Ritu Patil
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
You are on page 1/ 22

a

Attempt any FIVE the following


of

List any four features of Java script.


:
Ans Features of Java script

1. JavaScript is a object-based scripting language.


2. Giving the user more control over the browser.
3. It Handling dates and time.
4. It Detecting the user's browser and OS,
5. It is light weighted.
6. Client -Side Technology
7. JavaScript is a scripting language and it is not java.
8. JavaScript is interpreter based scripting language.
9. JavaScript is case sensitive.
10. JavaScript is object based language as it provides predefined objects.
11. Every statement injavascript must be terminated with semicolon (:).
12. Most of the javascript control statements syntax is same as syntax of
control statements in C language.
13. An important part of JavaScript is the ability to create new functions
within scripts. Declare function 1n JavaScript
using function keyword.
b List the comparison operators in Java script.
RegExp - represents regular expression
c) Write a simplecalculator program using switch case in JavaScript. 2M

Ans <html> 2M fo

relevar
<body>
<Script> progran

const =parseFloat(prompt("Enter
numberl first number: "):
const number2 =parseFloat(prompt("Enter second number: ")):

const operator
let result;
=prompt("Enter operator (either +, , *,/or%): ");

switch (operator) (
case "+":

result = numberl + number2;


document. write(result);

break;

case "-":

result =numberl - number2;

document. write(result);

break:

case "

result = numberl *number2;


document. write(result):

break;

case "/":

result =numberl /number2;


document.write(result):
break;

case "%"
result =numberl % number2;
document.write(result);
break;

Page No:2 | 2:

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATIOON


(Autonomous)
(ISO/1EC-27001-2013 Certified)

default:

document. write("Invalid operator"):


break:

<script>

<body>
<htmb
Program:Write a Javascript code to find out factorial of entered number.

<htm>
<head>
<script language="javascript" type="ext/javascript"'>
var i=parselnt(prompt("Enter Number"):
var a;
var fact=l;
for (a=1;a<=i; a++)

fact=fact*a;

document.write("Factorial: "+fact):
a Explain getter and setter properties in Java script with suitable example. 4M
Ans Property getters and setters Explanation
1. The accessor properties. They are essentially functions that work on : 2M
getting and setting a value.
2. Accessor properties are represented by "getter" and "setter"methods. In
an object literal they are denoted by get and set.
let obj = {

get propName)

{
ll getter, the code executed on getting obj-prop Name

set propName(value) {
Ilsetter, the code executed on setting obj-propName =value

3. An object property is a name, value and a set of attributes. The value


may be replaced by one or twomethods,known as setter andagetter.
4. When program queries the value of an accessor property, Javascript
invoke getter method(passing no arguments). The retuen value of this
method become the value of the property access expression.
5. When program sets the value of an accessor property. Javascript invoke
the setter method,passing the value of right-hand side of assignment. This
method is responsible for setting the property value.
• If property has both getter and a setter method, it is read/write
property.

• If property has only a getter method , it is read-only property.


• property has only a setter method , it is a write-only property.
If

6. getter works when obj.propName is read, the setter when it is assigned.–


Example:
<htmb
Example:
<htmb

Page 5|30

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION


(Autonomous)
(ISO/IEC 27001 - 2013 Certified)

<head>
<title>Functions</title>

<body> Example :
<script language="Javascript">
2M
var myCar =(
/*Data properties */
defColor: "blue",
defMake: "Toyota",
(Any other
/* Accessor properties (getters) */ example can
get color() be
{
return this,.defColor; considered)

get make()
returnthis.defMake:

/* Accessor properties (setters) */


set color(newColor) {
this.defColor =
newColor;

set make(newMake)
this.defMake newMake;=
):

document. write("Car color:"+ myCar.color +"Car Make: "+myCar. make)


/* Calling the setter accessor properties */
myCar.color = "red":

myCar.make ="Audi":
/*Checking the new values with the getter accessor properties */
document. write("<p>Carcolor:" +
myCar.color);// red
document. write(" Car Make: "+myCar.make); /Audi
</script>
head>
K/body>
<Ahtmb
1.4 Operators and Expressions:
Javascript includes following categories of operators:

1. Arithmetic operators

2. Comparison operators
3. Logical operators
4. Assignmentoperators
5. Ternary operators

1. Arithmetic operators:

Arithmetic operators are used to perform arithmetic on numbers:

Operator Description

+ Addition

Subtraction

Multiplication

Division

Modulus (Division Remainder)

tt Increment (increment operands value by one)

Decrement (decrement operands value by one)


2.Comparison operators

Operator Description

Compares the quality of two operands without considering types

Compares the quality of two operands with types

Compare inequality of two operands

greater than

less than

greater than or equal to

less than or equal to


3.Logical Operators:

Operator Description

logical AND. check whether two operands are non-zero. If yes then returns
&& Iotherwise 0.
It

logical OR. It check whether any one of the two operands is non-zero.

logical NOT.It reverse the Booleanresult of the operand


4.Assignment Operators:
Assignment operators assign values to JavaScript variables.

Operator Example Same As


a=b a=b
a+=b a=a+b
a-=b a=a-b
A*=b a=a*b
A/=b a=a/b
%= a%=b a=a%b
5.Ternary Operator:

Syntax:
<condition> ? <valuel>:<value2>

Ternary operator starts with conditional expression followed by ? operator. Second part

(after ? and before :operator) will be executed if condition turns out to be true. If condition
becomes false then third part (after :) will be executed.
Write a Java script to create person object with properties firstname, 2M
lastname, age, eyecolor, delete eyecolor property and display remaining
properties of personobject.
Ans <htmb Create

person
<body> object :1M
<script>

var person ={
firstname:"John",

lastname:"Doe",

age:50,

eyecolor:"blue"

): Delete and
display
delete person.eyecolor; //delete person eyecolor
properties :
document. write("After delete "+ person.firstname +" "+ person.lastname +" IM
+person.age +""+ person.eyecolor);

</script>

<body>

K/htm>
C Write a Java seript program which computes,the average marks of the 4M
following students then, this average is used to determinethe corresponding
grade.
Student Name Marks
Sumit 80
Kalpesh 77
Amit 88
Tejas 93
Abhishek 65

The grades are computed as follows :


Range Grade
<60 E
D

<80
<90 B
<100
Ans <htmb Correct

<head>
logic : 2M,
Correct
<title>Compute the average marksand grade</title> 2M
Syntax:

<head>
(any other
logiccan be
<body>
considered)
<script>

var students = [[Summit', 80]. ['Kalpesh, 77]. ['Amit', 88). (Tejas', 93).
['Abhishek', 65]1:

var Avgmarks =0;


for (var i-0; i< students.length; i++) (
Avgmarks += students[il[1):

var avg = (Avgmarks/students. length);


document. write("Average grade: "+ (Avgmarks)/students.length):
document.write("<br>");

if (avg < 60){


document.write("Grade : E");

else if (avg <70) (


document.
write("Grade : D");

else if (avg < 80) (

document. write("Grade : C"):

)else if (avg < 90) (

document. write("Grade : B"):

)else if (avg < 100) {


document. write("Grade : A");

</script>

<body>
</html>

Output (Optiona)

Average grade: 80.6


Grade:B
2.4.9 Finding a Unicode of a Character:
i)charCodeAt():This function returns the Unicode value of the character at specified
position.

Syntax:

String.charCodeAt(x);

Program:
<html>
<body>
<script language="javascript"type="text/javascript"'>
var a="THIS IS COMPUTER DEPARTMENT";
document.write("Unicode value of character :"+a.charCodeAt(3);
</script>

</body>
</html>

Output:

D ileFusvCPCOmputet20GrapticavCR)MsaTES3OMtraiCS6/s5K,CSChaptes202/SingichaCodeAG,tm

Uniode value of character : 83

Activate Windows
ii) fromCharCode():This method convert a given Unicode number into a character.

Syntax:
String.fromCharCode(n1,n2,n3..,.nx)

Programn:

<html>
<body>

<script language="javascript" type="text/javascript">


document.write("Uniode value:"+String.fromCharCode(83);
document.write("<br>Uniode value:"+String.fromCharCode(84,11 5,65);
</script>

</body>
</html>

Output:

onCeCaanl

cSs/Chagte202/StrngtiomChaCode0.ntmi

Uniode value : S
Uniode value: TsA

Activate Windows
Go to Setings to ciahe Wndo

Searc the web and Windows


e Write Javascript to call function from HTML. 2M
Ans <htm> Function
declaration :
<head>
IM,
<title> Calling function from HTML<title>

<script> Function
call from
function welcome()
HTML: IM

alert("Welcome students");
(Any other
example
allowed)
function goodbye()

alert("Bye");

Page 3 |30

MAHARASHTRA STATE BOARDOF TECHNICAL EDUCATION


(Autonomous)
(ISOIEC-27001- 2013 Certifed)

<script>

<head>

<body onload="welcome()" onunload="goodbye()">

<body>

<htmb
f Write a Javascript to design a form to accept values for user ID & password. 2M
Sort()) method sorts the elements of an array in place and returns the sorted array.When
sort() without argument is called. It will sort elements in alphabetical order.

Syntax:
Array_name.sort();

CLIENT SIDESCRIPTING LANGUAGE (CSS)-UNIT 2 (ARRAY) MRS. S.S. KADAM

Program: Write javascript code to print number array element by using sort
method

<html>
<head>

<script language="javascript" type="text/javascript">


var arr1-[8,6,9,4,2];
document.write("Array element before sorting....");

document.write (arr1+"<br>");
arr1.sort(0:

document.write("Array element after sorting...."):


document.write(arr1);
</script>

</head>
<body>

</body>
</html>

FUsVCPr

Array element before sorting....8,6,9,4,2


Array element after sorting....2,4,6,8,9
Reverse() Method:
Reverse() method is used to display sorted list manner i.e.in
in reverse

descending order. It will return the reversed single value of the array.

Syntax: array.reverse();

Program:Writea javascript code to sort array elements in descending order by


using reverse order.

<html>
<head>
<script language="javascript" type="text/javascript">
var arr1=new Array(9,2,3,8,1,7,5);
document.write("Array element before sorting:<br> "+arr1);
var a=arr1.sort();
a.reverse();

document.write("<br>Array element after sorting: <br>"+a):


</script>

</head>
<body>

</body>
</html>

Output:

Divceycompuetizodeapt sethachin

Array element before sorting:


9,2,3,8,1.7.5
Array element after sorting:
9,8,7.5.3,2,1

Activate Windows
8
|Attemptany THREE ofthe following : M
12
4M
Differentiate between concat() and join() methods of array object.
Ans concat) join()

Array elements can be combined by Array elements can be combined by


using concat() method of Array using join() method of Array object.

object.

The concat() method separates each The join() method also uses a comma
value with a comma. to separate values, but you can
specify a character other than a

comma to separate values.

Eg: Eg:

var str =cars.concat() var str =cars.join()


The value of str in this case is

The value of str is "BMW Audi Maruti


'BMW,Audi, Maruti'
<> HELLo.html > html

1 <!DOCTYPE html>
2 <html lang="en"

>
3 <head>
<meta charset="UTF-8">
5 <meta name="viewport" content="width=device -width, initial -scale=1.0">
6 <title>Character to Unicode Converter</title>
7 </head>
8 <body>
<script>
10 var a=parseInt(prompt ("Enter the number"));
11 document.write ("The character is "+String.fromCharCode (a)+"<br");
12
13 var b=prompt ("Enter the character");
14 document. write("The unicode value of the character is "+b.charCodeAt (b));
15 </script>
16 </body>
17 </html>
<> HELLO.html > html > body > br

1 <! DOCTYPE html>


2 <html lang="en"

>
3 <head>
<meta charset="UTF -8">
5 <meta name="viewport" content="width=device -width, initial -scale=1.0">
6 <title>HEHE</title>
7 </head>
<body>
<label for="firstName'">First Name:</label>
1 <input type="text" id="firstName" name="firstName" required> <br> <br>
11
12 <label for="middleName ">Middle Name:</label>
13 <input type="text" id="middleName" name="middleName" ><br><br>
14
15 <label for="surname">Last Name:</label>
16 <input type="text" id="surname" name="surname" required><br><br>
17
18 <button type="submit" >Submit</button>
19 </body>
20 </html>
Program:
Write a Javascript function to count the number of vowels in a given string.
<html>
<body>
<script language="javascript" type="text/javascript">
function vowelsCount()

var a=prompt("'enter string");


var i,c,count=0;

for(i=0;i<a.length;i++)

c=a.charAt(i);

|
if(c=="a" |c=="A"| c=="e"| c=="E"||c==""|c==""|

{
| |c=="o"| |c=="O"| |c=="u"||c=="U"

count+t;

document.write("'entered String is :"+a);


document.write("<br>Total vowels in the string is:"+count);

vowelsCount();
</script>
</body>
</html>

Output:

Fe FUSVCPICOmputets20Graphics/SvCPMSSTES20MatarialrCSs/sSK.C apter2 shtmi

entered String is : hello


Total vowels in the string is :2

Activate Windows

You might also like