CSS Ut1 Answers
CSS Ut1 Answers
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 "+":
break;
case "-":
document. write(result);
break:
case "
break;
case "/":
case "%"
result =numberl % number2;
document.write(result);
break;
Page No:2 | 2:
default:
<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
Page 5|30
<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:
set make(newMake)
this.defMake newMake;=
):
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:
Operator Description
+ Addition
Subtraction
Multiplication
Division
Operator Description
greater than
less than
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.
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
<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:
</script>
<body>
</html>
Output (Optiona)
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
Activate Windows
ii) fromCharCode():This method convert a given Unicode number into a character.
Syntax:
String.fromCharCode(n1,n2,n3..,.nx)
Programn:
<html>
<body>
</body>
</html>
Output:
onCeCaanl
cSs/Chagte202/StrngtiomChaCode0.ntmi
Uniode value : S
Uniode value: TsA
Activate Windows
Go to Setings to ciahe Wndo
<script> Function
call from
function welcome()
HTML: IM
alert("Welcome students");
(Any other
example
allowed)
function goodbye()
alert("Bye");
Page 3 |30
<script>
<head>
<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();
Program: Write javascript code to print number array element by using sort
method
<html>
<head>
document.write (arr1+"<br>");
arr1.sort(0:
</head>
<body>
</body>
</html>
FUsVCPr
descending order. It will return the reversed single value of the array.
Syntax: array.reverse();
<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();
</head>
<body>
</body>
</html>
Output:
Divceycompuetizodeapt sethachin
Activate Windows
8
|Attemptany THREE ofthe following : M
12
4M
Differentiate between concat() and join() methods of array object.
Ans concat) join()
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
Eg: Eg:
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
>
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()
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;
vowelsCount();
</script>
</body>
</html>
Output:
Activate Windows