CSS test 1 QB SOLVED
CSS test 1 QB SOLVED
chapter: 1
• It is light weighted.
--> == equal to
!= not equal to
• Null: This value can be assigned by reserved word ‘null’. It means no value.
• Object: It is the entity that represents some value. Ex: Form is an object on which some
• Object is entity. In JavaScript document, window, forms, fields, buttons are some properly used
objects.
Property:
• For example, a form object has a title, a width, and a height—to mention a few properties
Method:
• For example, a Submit button on a form is an object. Its Submit label and the dimensions of the
• If you click the Submit button, the form is submitted to the server-side application. In other
words, clicking the Submit button causes the button to process a method.
-->• JavaScript can be implemented using JavaScript statements that are placed within the <script>...
• You can place the <script> tags, containing your JavaScript, anywhere within your web page, but it
is normally recommended that you should keep it within the <head> tags.
• The <script> tag alerts the browser program to start interpreting all the text between these tags as
a script.
<script ...>
JavaScript code
</script>
• Language − This aLribute specifies what scripNng language you are using.
• Type − This aLribute is what is now recommended to indicate the scripNng language in use
JavaScript code
</script>
-->1)console.log()
2)alert()
3)document.write()
4)innerHTML
7)Write a JavaScript to create person object with properties firstname, lastname, age, eye color,
delete eye color property and display remaining properties of person object.
--><html>
<body>
<script>
var person = {
firstname:"John",
lastname:"Doe",
age:50,
eyecolor:"blue"
};
person.lastname+" "
</script>
</body>
</html>
In JavaScript, accessor properties are methods that get or set the value of an object. For that, we use
The following example shows a getter defined on an object called person. The getter is called name,
let person = {
name: 'John',
get name() {
return this.name;
};
For example, let's say we have an object called "user" with a property called "name". We can define
const user = {
name: '',
set name(value) {
this.name = value;
},
};
10. Write a JavaScript program to check whether entered number is prime or not.
--><head>
<script type="text/javascript">
function prime()
var n,i,flag=true;
n=document.myform.n.value;
for(i=2;i<=n/2;i++)
if(n%i==0)
flag=false;
break;
}
if(flag==true)
alert(n+"is prime");
else
</script>
</head>
<body>
<form name="myform">
<br><br>
<br>
</form>
</body>
</html>
11) Write a JavaScript that accepts a number and displays addition of digits of that number in a
message box.
--><html>
<body>
<script>
</script>
</body>
</html>
-->•prompt() method is used to display a dialogue box to the user to prompt them to an input.
•It has two buttons “OK” and “CANCEL”, if the user click on the “OK” button then it will return the
inputed value , if the user clicks on the "CANCEL” button then it will return a null value
• Syntax: prompt(text)
Example:
<script>
document. Write(name);
</script>
13) Give syntax of and explain the use of small “with” clause.
-->“with” clause is used to directly access the properties and method of an object.
Syntax:
with (object)
//object
Example:
<script>
with(person){ docment.write(name);
docment.write(age);
</script>
4 marks
chapter: 1
1. Write a JavaScript program which computes average marks of the student and according to
average
--><html>
<head>
</head>
<body>
<script>
var Avgmarks = 0;
Avgmarks += students[i][1];
document.write("<br>");
document.write("Grade : E");
document.write("Grade : D");
document.write("Grade : C");
document.write("Grade : B");
document.write("Grade : A");
</script>
</body>
</html>
-->• for loop is a method available for arrays in JavaScript. It allows you to iterate over each
for...in loop:
o The for...in loop allows you to access each property of an object. It iterates over the
enumerable properties of an object, and for each property, the loop assigns the property
Difference :
a. First, the for...in can loop through both Arrays and Objects while the for...of can only loop
b. The second and the biggest difference between both of these statements are, by default,
the for...in iterates over property names and the for...of iterates over property values.
1. The accessor properties. They are essentially functions that work on getting and setting a value.
2. Accessor properNes are represented by ―geLer‖ and ―seLer‖methods. In an object literal they
are
get –It is used to define a getter method to get the property value
set –It is used to define a setter method to set / change the property value
let obj =
get propName() {
},
set propName(value) {
};
value may be replaced by one or two methods, known as setter and a getter.
Example of getter
const student
firstname: ‗abc‘,
get getname()
{
return this.firstname;
};
Example of setter
const student
firstname: ‗abc‘,
set changename(nm)
this.firstname=nm;
};
first number:
second number:
The user enters two numbers in respective text boxes. Write a JavaScript such that when user clicks
"add", a message box displays sum of two entered numbers, if the user clicks on "sub”. Message
box displays subtraction of two numbers and on clicking “mul” the message box displays
--> <html>
<head>
<script>
function add()
num1 = parseInt(document.getElementById("firstnumber").value);
num2 = parseInt(document.getElementById("secondnumber").value);
r= num1 + num2;
alert(r);
function sub()
num1 = parseInt(document.getElementById("firstnumber").value);
num2 = parseInt(document.getElementById("secondnumber").value);
r = num1 - num2;
alert(r);
function mul()
num1 = parseInt(document.getElementById("firstnumber").value);
num2 = parseInt(document.getElementById("secondnumber").value);
r = num1 * num2;
alert(r);
</script>
</head>
<body>
<fieldset>
<button onclick="add()">Add</button>
<button onclick="sub()">Sub</button>
<button onclick="mul()">Mul</button>
</fieldset>
</body>
</html>
20. Write a JavaScript program to check whether a number is positive, negative or zero using switch
case.
<html>
<body>
<script type="text/javascript">
switch (Math.sign(num))
case 1:
break;
case -1:
break;
default:
</script>
</body>
</html>
6. Write HTML script that displays textboxes for accepting username and password. Write proper
i) All textboxes must get disabled and change the color to ‘RED; and with respective labels
ii) Prompt the error message if the password is less than six characters
--><html>
<head>
<script>
function disableTxt()
document.getElementById("un").disabled = true;
document.getElementById('un').style.color = "red";
document.getElementById('aaa').style.color = "red";
document.getElementById("pass").disabled = true;
document.getElementById('pass').style.color = "red";
document.getElementById('bbb').style.color = "red";
function validateform()
var username=document.myform.username.value;
var password=document.myform.password.value;
if (username==null || username=="")
return false;
else if(password.length<6)
return false;
</script>
</head>
<body>
validateform()" >
<label id = "aaa">Username:</label>
<label id = "bbb">Password:</label>
<br>
<br>
<button onclick="disableTxt()">Disable Text field</button>
</form>
</body>
</html>
chapter 2
2 marks
1)Write a JavaScript that initialize an array called flowers with the names of 3 flowers. The script then
<html>
<head>
</head>
<body>
<script>
flowers[1] = 'Mogra';
flowers[2] = 'Hibiscus';
document.write(flowers[i] + '<br>');
</script>
</body>
</html>
2) State the meaning of "Defining a function". Explain with the help of an example.
--> • A function is a block of code that takes some input to perform some certain computation.
• The main purpose of the function is to put commonly used or repeatedly used task in a function, so
instead of writing the code again and again we can call it instead.
Syntax:
//code
Example:
<script>
function add(num1,num2)
add(1,2);
</script>
<html>
<body>
<form name="login">
</form>
<script language="javascript">
function display()
:"+login.pswrd.value);
</script>
</body>
</html>
4)Write a program to accept the marks of 10 subjects from the user and store it in array. Sort them
and display
--><html>
<body>
<script>
a = new Array();
marks?");
for(i=0;i<length;i++)
for(i=0;i<length;i++)
document.write("</br>");
are<br\>");
a.sort();
for(i=0;i<length;i++)
document.write("</br>"); }
</script>
</body>
5) Write a JavaScript that will replace following specified value with another value in the string
--> <html>
<head>
<body>
<script>
document.write(newStr);
</script>
</body>
</head>
</html>
-->
7) . Difference between concat() and join() method of array with example.
-->
chapter: 2
4 marks
1) Differentiate between substring() and substr() method of a string class. Give Suitable example of
each.
-->
i)
-->i) charCodeAt( )
ii) fromCharCode ( )
document.write(ch.charCodeAt( ));
Output: 97
Document.write(ch);
Output: a
3)Write a JavaScript to check whether a passed string is palindrome or not
-->function isPalindrome(str) {
Output: true
<html>
<body>
<h1>Palindrome</h1>
<p id="result"></p>
<script>
function checkPalindrome() {
var flag = 1;
flag = 0;
if (flag == 1) {
document.getElementById("result").innerHTML = "It is a
palindrome";
else {
document.getElementById("result").innerHTML = "It is not a
palindrome";
</script>
</body>
</html>
4) Explain how to add and sort elements in array with suitable example.
In JavaScript, you can add elements to an array using various methods, such as push(), unshift(), or
Using push():
The push() method adds one or more elements to the end of an array and returns the new length of
the array.
Using unshift():
The unshift() method adds one or more elements to the beginning of an array and returns the new
Using splice():
This method can be used to add new items to an array, and removes elements from an array.
Syntax:
arr.splice(start_index,removed_elements,list_of_elemnts_to_be_added);
Parameter:
•The first parameter defines the position where new elements should be added (spliced in).
The length property provides an easy way to append a new element to an array.
Example
<script>
document.write(fruits+"<br>");
fruits[fruits.length] = "Kiwi";
document.write(fruits+"<br>");
fruits[fruits.length] = "Chikoo";
document.write(fruits);
</script>
JavaScript provides the sort() method to sort the elements of an array in place and returns the
sorted array.
Example
numbers.push(7);
• The JavaScript string charAt() method is used to find out a char value present at the specified index
in a string.
• The index number starts from 0 and goes to n-1, where n is the length of the string. The index value
• Syntax
String.charAt(index)
Example1
<html>
<body>
<script>
document.writeln(str.charAt(4));
</script>
</body>
</html>
• The JavaScript string charCodeAt() method is used to find out the Unicode value of a character at
• The index number starts from 0 and goes to n-1, where n is the length of the string.
• It returns NaN if the given index number is either a negative number or it is greater than or equal
• Syntax : string.charCodeAt(index)
<html>
<head>
</head>
<body>
</script>
</body>
</html>
6)Write an HTML script that accepts Amount, Rate of interest and Period from user. When user
submits the information a JavaScript function must calculate and display simple interest in a
--><html>
<body>
<script>
var SI =(P*N*R)/100;
</script>
</body>
</html>
OR
<html>
<head>
<script>
function interest()
var P, N, R;
P= parseInt(document.getElementById("pr").value);
N = parseInt(document.getElementById("period").value);
R = parseInt(document.getElementById("ri").value);
var SI =(P*N*R)/100;
</script>
</head>
<body>
</body>
</html>
7)Write HTML script that displays textboxes for accepting username and password. Write proper
i) All textboxes must get disabled and change the color to ‘RED; and with respective labels
ii) Prompt the error message if the password is less than six characters
--><html>
<head>
<script>
function disableTxt()
document.getElementById("un").disabled = true;
document.getElementById('un').style.color = "red";
document.getElementById('aaa').style.color = "red";
document.getElementById("pass").disabled = true;
document.getElementById('pass').style.color = "red";
document.getElementById('bbb').style.color = "red";
function validateform()
var username=document.myform.username.value;
var password=document.myform.password.value;
if (username==null || username==""){
return false;
}else if(password.length<6){
return false;
</script>
</head>
<body>
validateform()" >
<label id = "aaa">Username:</label>
<label id = "bbb">
Password:
</label>
<br>
<br>
</form>
</body>
</html>
chapter 3
2 marks
1. `submit`
2. `reset`
3. `focus`
4. `blur`
5. `change`
6. `input`
7. `keydown`
8. `keyup`
onclickevent: This event occurs when a mouse button is clicked on or over a form element.
Example:
ondblclickevent: This event occurs when a mouse button is double clicked on or over a form element.
Example:
onmousedownevent: This event executes when a mouse button is clicked while cursor is over an
element.
Example:
onmouseupevent: This event executes when a mouse button is released while the cursor is over an
element.
Example:
onmouseoverevent: This event executes when mouse cursor moves onto an element.
Example:
<input type="text" onmouseover=" function ()"> onclickevent: This event occurs when a mouse
button is clicked on or over a form element.
Example:
ondblclickevent: This event occurs when a mouse button is double clicked on or over a form element.
Example:
onmousedownevent: This event executes when a mouse button is clicked while cursor is over an
element.
Example:
onmouseupevent: This event executes when a mouse button is released while the cursor is over an
element.
Example:
onmouseoverevent: This event executes when mouse cursor moves onto an element.
Example:
<input type="text" onmouseover=" function ()">
<html>
<head>
</head>
<body bgcolor="Red">
<Center>
<h2>Login Form</h2>
</center>
<form name="form1">
<table>
<tr>
<td><b>Name:</b></td>
</tr>
<tr>
<td><b>Password:</b></td>
</tr>
<tr>
</tr>
</table>
</form>
</body>
</html>
<script type="text/javascript">
function getcube()
var number=document.getElementById("number").value;
alert(number*number*number);
</script>
<form>
</form>
chapter- 3
4 marks
1). Write a JavaScript to create rollover effect that involves text and images. When the user places his
or her mouse pointer over a book title, the corresponding book images appears .
--><html>
<head>
<title>
rollovers</title>
</head>
<body>
<tbody>
<tr valign="top">
<td width="50%">
name="clr"></a></td>
<td><a onmouseover="document.clr.src='blue.png' ">
<b><u>Motivational book</u></b></a>
<br>
<b><u>Educational book</u></b></a>
<br>
</td>
</tr>
</tbody>
</table>
</body>
</html>
2). Write a HTML script which displays 2 radio buttons to the users for fruits and vegetables and 1
option list. When user select fruits radio button list should present only fruits to the user & when
user select vegetables radio button option list should present only vegetables names to the user.
--><html>
<head>
<title>HTML Form</title>
function updateList(ElementValue)
with(document.forms.myform)
if(ElementValue == 1)
optionList[0].text="Mango";
optionList[0].value=1;
optionList[1].text="Banana";
optionList[1].value=2;
optionList[2].text="Apple";
optionList[2].value=3;
}
if(ElementValue == 2)
optionList[0].text="Potato";
optionList[0].value=1;
optionList[1].text="Cabbage";
optionList[1].value=2;
optionList[2].text="Onion";
optionList[2].value=3;
</script>
</head>
<body>
<p>
<option value=1>Mango
<option value=2>Banana
<option value=3>Apple
</select>
<br>
onclick="updateList(this.value)">Fruits
onclick="updateList(this.value)">Vegetables
<br>
</p>
</form>
</body>
</html>
3) Insert an image into a wepage. Write a script which displays the message when the mouse is over
the image. The coordinates of the mouse should be displayed if click attempted on the image
--><html>
<head>
<script type="text/javascipt">
function my_fun1()
function my_fun2()
points.innerText="("+event.offsetX+","+event.offsetY+")";
</script>
</head>
<center>
<span id="points">(0,0)</span>
style="position:absolute;top:50;left:90">
</center>
</body>
</html>
• These two event types will help you create nice effects with images or
even with text as well. The onmouseover event triggers when you bring
your mouse over any element and the onmouseout triggers when you move
your mouse out from that element. Try the following example.
<html>
<head>
function over() {
function out() {
</script>
</head>
<body>
</div>
</body>
</html>
4). Explain following form control / elements with example Button, Text, TextArea, Select, Checkbox,
Form.
There are several types of button, which are specified by the type
attribute:
2. Submit, which is associated to the form and which starts the loading of the file assigned to the
action attribute.
A Button object also represents an HTML <button> element which is specified as follows:
Example:
<html>
<body>
<form>
</form>
<script>
function msg()
alert("Hello world!");
</script>
</body>
</html>
Text:
assign_value" />
Example:
<script type="text/javascript">
function changeText()
document.getElementById('vp').innerHTML = userInput;
</script>
</script>
TextArea:
The <textarea> tag indicates a form field where the user can enter a large amount of text.
Example:
<html>
<body>
disabled="yes">
As you can see many times word wrapping is often the desired look
for your textareas. Since it makes everything nice and easy to read
</textarea>
</body>
</html>
Checkbox:
<input> elements of type checkbox are rendered by default as boxes that are checked (ticked)
when activated. A checkbox allows you to select single values for submission in a form (or not).
1. Checked
2. Unchecked
Example:
<html>
<body>
<div>
<br>
checked>
<label for="ej">Electronics</label><br>
<button onclick="validate();">Validate</button>
</div>
<div id="status">
</div>
<script>
function validate()
statusText = statusText +
elements[index].value+"="+elements[index].checked+"<br>";
document.getElementById("status").innerHTML = statusText;
</script>
</body>
</html>
Select:
Form SELECT elements (<select>) within your form can be accessed and manipulated in JavaScript
page.
Example:
<html>
<body>
<option>Computer Engineering</option>
<option>Information Technology</option>
<option>Chemical Engineering</option>
<option>Electronics &TeleComm.</option>
</select>
dropdown list.</p>
<script>
function myFunction()
var x = document.getElementById("programs").options[2].disabled
= true;
document.getElementById("programs").options[2].style.color =
"red";
</script>
</body>
</html>
Form:
A form is a section of an HTML document that contains elements such as radio buttons, text boxes
and option lists. HTML form elements are also known as controls.
Elements are used as an efficient way for a user to enter information into a form. Typical form
The <form> element can contain one or more of the following form
elements:
<label>
· <legend>
Syntax: