Question Bank Css
Question Bank Css
2Marks each:-
1. List any four features of Java script.
2. Write Java script to create person object with properties firstname, lastname, age,
eyecolor, delete eye color property and display remaining properties of person object.
3. Write a JavaScript that displays first 20 even numbers on the document window.
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<div id="vedant">
</div>
<script>
var arr=new Array(20);
var a=0;
i=0;
do
{
if(i%2==0)
{
arr[a]=i;
a++;
document.write(i+"<br>");
}
i++;
}while(arr.length<=20);
</script>
</body>
</html>
4. Write a program to print sum of even numbers between 1 to 100 using for loop.
<html lang="en">
<head>
</head>
<body>
<script>
var sum=0;
for(i=0;i<=100;i++){
if(i%2==0)
{
sum=sum+i;
}
}
document.write("Sum of Even Numbers between 1 to 100 = "+sum);
</script>
</body>
</html>
.5. Write a Java script that initializes an array called flowers with the names of 3
flowers. The script then displays array elements.
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<script>
const arr=["Rose","Lilly","SunFlower"];
for(i=0;i<arr.length;i++)
{
document.write(arr[i]+"<br>");
}
</script>
</body>
</html>
6. Write the use of CharAt() and indexof() with syntax and example.
7. Write a Java script that will replace following specified value with another
value in a string.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<p id="demo">
I will pass
</p>
<script>
var msg=document.getElementById("demo").innerHTML
document.write(msg);
var str=msg.replace("pass","fail");
document.write("<br/>"+str);
</script>
</body>
</html>
8. Write a JavaScript function to count the number of vowels in a given string.
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<script>
var str=prompt("Enter the String","Vedant");
var arr=str.split("");
count=0;
for(a=0;a<arr.length;a++){
i=arr[a];
if(i=='a'||i=='e'||i=='i'||i=='o'||i=='u'|| i=='A'||i=='E'||i=='I'||
i=='O'||i=='U')
{
count++;
} }
document.write(count);
</script>
</body>
</html>
9 . Write a function that prompts the user for a color and uses what they select to set the
background color of the new webpage opened .
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body id="body">
<script>
color = prompt("Enter color name","black")
document.write("color : "+color)
color=color.toLowerCase();
document.getElementById("body").style.backgroundColor = color;
</script>
</body>
</html>
10.Write a javascript function that accepts a string as a parameter and find the
length of the string.
Ans.
<html>
<body>
<script>
function sayHello(msg){
sayHello(x);
</script>
</body>
</html>
11. Develop javascript to convert the given character to unicode and vice-versa.
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<script>
var str=prompt("Enter the Character to check the its unicode","A");
var i=str.charCodeAt();
document.write("The Unicode for "+str+" is "+i+ "<br/><br/>");
</script>
</body>
</html>
12 . Write a javascript program to check whether entered number is prime or not.
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<script>
var a=parseInt(prompt("Enter the number to check wheter its prime or
not"));
b=1;
do{
b++;
}while(a%b!=0);
if(a==b)
{
document.write(a+" is a Prime Number");
}
else
{
document.write(a+" is not a Prime Number");
}
</script>
</body>
</html>
4m each:-
1. Write a javascript program to validate user accounts for multiple set of user ID
and password (using swith case statement).
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<div id="first" align="center">
<label for="first1">Enter the User Id</label>
<input type="text" id="first1"/>
</div><br>
<div id="Second" align="center">
<label for="Second2">Enter the Password</label>
<input type="text" id="Second2"/><br/><br/>
<Button id="bt1" onclick=check()>Login</Button>
</div>
<script>
function check(){
var a=document.getElementById("first1").value;
var b=document.getElementById("Second2").value;
var msg="Login Sucessful";
switch(a)
{
case "vedant" : if(b=="121")
break;
default : msg="Login unsucessful";
}
alert(msg);
}
</script>
</body>
</html>
2. Write a javascript function to generate Fibonacci series till user defined limit.
<html>
<body>
<script>
var t1 = 0;
var t2 = 1;
t3 = t2 + t1;
document.write(" "+t3);
t1=t2;
t2=t3;
</script>
</body>
</html>
OR
USER DEFINED
<html>
<body>
<script>
var t1 = 1;
var t2 = 0;
document.write(""+t2);
var x = parseInt(prompt("Enter max length for fibonacci series","6"));
t3 = t1 + t2;
document.write(" "+t3);
t1=t2;
t2=t3;
</script>
</body>
</html>
3. Write a JavaScript that find and displays number of duplicate values in an array.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>V</title>
</head>
<body>
<script>
count = 0;
var arr1 = new Array();
var arr = [20,20,20, 10, 10, 10, 10, 10, 10, 10, 40, 40, 40, 30, 30,
30];
for (i = 0; i < arr.length; i++)
{
for (j = i + 1; j < arr.length; j++)
{
if (arr[i] == arr[j])
{
z = 0;
c = 0;
do {
if (arr[i] == arr1[z])
{
c = 1;
}
z++;
}
}
}
document.write("There are " + count + " duplicate values <br>");
for (i = 0; i < arr1.length; i++) {
document.write(arr1[i] + "<br>");
}
</script>
</body>
</html>
4. . Write a Java script program which computes, the average marks of the
following students then, this average is used to determine the corresponding
grade.
StudentName Marks
Sumit 80
Kalpesh 77
Amit 88
Tejas 93
Abhishek 65
The grades are computed as follows :
Range Grade
< 60 E
< 70 D
< 80 C
< 90 B
< 100 A
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<p id = "demo"></p>
<script>
const name = ["Sumit", "Kalpesh", "Amit", "Tejas", "Abhishek"]
marks = [80, 77, 88, 93, 65]
for ( let i = 0 ; i< name.length ; i++)
{
average = marks[i]
5. Write a Java script to design a form to accept values for user ID & password.
6. <!DOCTYPE html>
7. <html lang="en">
8. <head>
9. <meta charset="UTF-8">
10. <meta http-equiv="X-UA-Compatible" content="IE=edge">
11. <meta name="viewport" content="width=device-width, initial-
scale=1.0">
12. <title>chap 03 1</title>
13.</head>
14.
15.<body>
16. <form action="">
17. <label for="uID">UserID</label>
18. <input type="text" id="uID" size="25" maxlength="10" value="">
19. <br><br>
20. <label for="pswd">Password</label>
21. <input type="text" id="pswd" size="25" maxlength="6" value="">
22. <br><br>
23. <button id="sbmt">Submit</button>
24. <input type="reset" id="rst">
25. </form>
26.
27. <script>
28. var sbmt_s = document.getElementById("sbmt");
29. sbmt_s.addEventListener("click", validate, false);
30.
31. function validate() {
32. var uid = document.getElementById("uID");
33. var pswd = document.getElementById("pswd");
34. if (uid.value == "" || pswd.value == "") {
35. document.write("Please dont keep Field blank")
36.
37. }
38. else {
39. document.write("Login Succesful")
40. }
41. }
42. </script>
43.</body>
44.
45.</html>
46.
6.Write HTML Script that displays textboxes for accepting Name, middlename, Surname of the
user and a Submit button. Write proper JavaScript such that when the user clicks on submit
button
i) all texboxes must get disabled and change the color to “RED”. and
with respective labels.
ii) Constructs the mailID as <name>.<surname>@msbte.com and
displays mail ID as message. (Ex. If user enters Rajni as name and Pathak as
surname mailID will be constructed as rajni.pathak@msbte.com) .
b) <!DOCTYPE html>
c) <html lang="en">
d) <head>
e) <meta charset="UTF-8">
f) <meta http-equiv="X-UA-Compatible" content="IE=edge">
g) <meta name="viewport" content="width=device-width, initial-
scale=1.0">
h) <title>chap 03 6</title>
i) </head>
j) <body>
k) <form action="" method="get">
l) <label for="name" class="l1">Name</label>
m) <input type="text" id="name" value="">
n) <br><br>
o) <label for="m_name" class="l1">Middlename</label>
p) <input type="text" id="m_name" value="">
q) <br><br>
r) <label for="s_name" class="l1">Surname</label>
s) <input type="text" id="s_name" value="">
t) <br><br>
u) <button type="button" id="sbmt">Submit</button>
v) <p id="email"></p>
w) </form>
x)
y) <script>
z) s_btn = document.getElementById("sbmt")
aa) s_btn.addEventListener("click", myFunc, false)
bb)
cc) function myFunc(){
dd) name_s = document.getElementById("name")
ee) m_name_s = document.getElementById("m_name")
ff) s_name_s = document.getElementById("s_name")
gg) for(i = 0; i < 3; i++){
hh) document.getElementsByTagName("label")
[i].style.color = "red"
ii) }
jj)
kk) name_s.disabled = true
ll) m_name_s.disabled = true
mm) s_name_s.disabled = true
nn)
oo) a = name_s.value
pp) b = m_name_s.value
qq) c = s_name_s.value
rr)
ss) document.getElementById("email").innerHTML =
a.toLowerCase() +"." + c.toLowerCase() +"@msbte.com"
tt) }
uu) </script>
vv) </body>
ww) </html>
xx)
7. Write HTML Script that displays dropdownlist containing options NewDelhi, Mumbai,
Bangalore. Write proper JavaScript such that when the user selects any options corresponding
description of about 20 words and image of the city appear in table which appears below on the
same page.
8. Write a HTML script which displays 2 radiobuttons to the users for fruits and
vegetable and 1 option list. When user select fruits radio button option list should present
only fruits names to the user & when user select vegetable radio button option list should
present only vegetable names to the user.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
<input type="radio" name="grp" id="Fruits" onclick="callme()"/>Fruits
<input type="radio" name="grp" id="Vegetable"
onclick="callme()"/>Vegetable
<select id="select1">
</select>
<script>
function callme(){
if(document.getElementById("Fruits").checked){
temp="<option> Apple</option> <br>"+ "<option>Banana</option>
<br>"+"<option>Cherry</option> <br>"+"<option>Stwabery</option> <br>";
document.getElementById("select1").innerHTML=temp;
}
if(document.getElementById("Vegetable").checked){
temp1="<option> Potato</option> <br>"+ "<option>Tomato</option>
<br>"+"<option>Cucumber</option> <br>"+"<option>Onion</option> <br>";
document.getElementById("select1").innerHTML=temp1;
}
}
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>chap 03 13</title>
</head>
<body>
<form action="" name="form1">
<label for="t1">First Number</label>
<input type="number" id="t1" value="">
<br><br>
<label for="t2">Second Number</label>
<input type="number" id="t2" value="">
<br><br>
<label for="t3">Answer</label>
<input type="number" id="t3" readonly>
<br><br>
<button type="button" id="add" onclick="addF()">Add</button>
<button type="button" id="sub" onclick="subF()">Sub</button>
<button type="button" id="div" onclick="divF()">Div</button>
<button type="button" id="mult" onclick="multF()">Mul</button>
</form>
<script>
function addF() {
var a = parseInt(document.getElementById("t1").value);
var b = parseInt(document.getElementById("t2").value);
c = a + b
document.getElementById("t3").value = c
}
function subF() {
var a = parseInt(document.getElementById("t1").value);
var b = parseInt(document.getElementById("t2").value);
c = a - b
document.getElementById("t3").value = c
}
function divF() {
var a = parseInt(document.getElementById("t1").value);
var b = parseInt(document.getElementById("t2").value);
c = a / b
document.getElementById("t3").value = c
}
function multF() {
var a = parseInt(document.getElementById("t1").value);
var b = parseInt(document.getElementById("t2").value);
c = a * b
document.getElementById("t3").value = c
}
</script>
</body>
</html>
10. Write a JavaScript function to insert a string within a string at a particular position
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<script>
var str="Hi how are you!!";
str=str.split(" ");
var str2=prompt("Enter your name");
var a=parseInt(prompt("Enter the position you want to insert your
name"));
str.splice(a,0,str2);
for(i=0;i<str.length;i++)
{
document.write(str[i]+" ");
}
</script>
</body>
</html>