Super 25 Css Rajan Sir - V2v-1
Super 25 Css Rajan Sir - V2v-1
1. Explain getter and setter properties in Java script with suitable example.
Ans:
Property getters and setters
1. The accessor properties. They are essentially functions that work on
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() {
// getter, the code executed on getting obj.propName
},
set propName(value) {
// setter, the code executed on setting obj.propName = value
}
};
3. An object property is a name, a value and a set of attributes. The value
may be replaced by one or two methods, known as setter and a getter.
4. When program queries the value of an accessor property, Javascript invoke
getter method(passing no arguments). The return value of this method
become the value of the property.
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.
If property has only a setter method , it is a write-only property.
Example:
<html>
<head>
<title>Functions</title>
<body>
<script language="Javascript">
var myCar = {
Color: "blue",
get color()
{ return this.Color;
},
set color(newColor)
{
this.Color = newColor;
}
};
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
document.write("Car color:" + myCar.color)
myCar.color = "red";
2. Explain prompt(), alert(), write() and confirm() method of Java script with
syntax and example.
Ans:
prompt()
The prompt () method displays a dialog box that prompts the visitor for input.
The prompt () method returns the input value if the user clicks "OK". If the
user clicks
"cancel" the method returns null. Syntax: window.prompt (text, defaultText)
Example:
<html>
<script type="text/javascript">
function msg(){
var v= prompt("Who are you?");
alert("I am "+v);
}
</script>
<input type="button" value="click" onclick="msg()"/>
</html>
confirm()
It displays the confirm dialog box. It has message with ok and cancel buttons.
Returns Boolean indicating which button was pressed Syntax:
window.confirm("sometext"); Example :
<html>
<script type="text/javascript">
function msg(){
var v= confirm("Are u sure?");
if(v==true)
{
alert("ok");
}
else{
alert("cancel");
}
}
</script>
<input type="button" value="delete record" onclick="msg()"/>
</html>
.
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
The alert() method displays an alert box with a message and an OK
button.The alert() method is used when you want information to come
through to the user. Syntax:
alert(message) example:
<html>
<body>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
alert("Hello\nHow are you?");
}
</script>
</body>
</html>
3. Write a Java script program which computes, the average marks of the
following students then, this average is used to determine the
corresponding grade.
Ans:
<html>
<head>
<title>Compute the average marks and grade</title>
</head>
<body>
<script>
var students = [['Summit', 80], ['Kalpesh', 77], ['Amit', 88], ['Tejas', 93],
['Abhishek', 65]];
var Avgmarks = 0;
for (var i=0; i < students.length; i++) {
Avgmarks += students[i][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>
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
4. Write the use of chatAt(),fromCharCode(), and indexof() with syntax and
example.
Ans:
charAt()
The charAt() method requires one argument i.e is the index of the character
that you want to copy.
Syntax:
var SingleCharacter = NameOfStringObject.charAt(index); Example:
var FirstName = 'Bob';
var Character = FirstName.charAt(0); //o/p B
indexOf()
concat() join()
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
Example: <script> Example: <script>
const arr1 = ["CO", "IF"]; const arr2 = var fruits = ["Banana", "Orange",
["CM", "AI",4]; const arr = "Apple", "Mango"]; var text =
arr1.concat(arr1, arr2); fruits.join();
document.write(arr); document.write(text); var text1 =
</script> fruits.join("$$");
document.write("<br>"+text1);
</script>
6. Write a JavaScript that will replace following specified value with another
value in string. String = “I will fail” Replace “fail” by “pass”.
Ans:
<html>
<head> <body> <script>
var myStr = ‘I will fail’;
var newStr = myStr.replace(fail, "pass");
document.write(newStr);
</script>
</body>
</head>
</html>
7. Write a Java Script code to display 5 elements of array in sorted order and
Write a javascript function to generate Fibonacci series till user defined
limit.
Ans:
<html>
<body>
<script>
var array =[5,1,9,7,5];
// sorting the array
sorted = array.sort();
document.write(sorted);
</script>
</body>
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
</html>
<html>
<head>
</head>
<body>
<script>
// declaration of the variables
var n1 = 0, n2 = 1, next_num, i;
var num = parseInt (prompt (" Enter the limit for Fibonacci Series "));
document.write( "Fibonacci Series: ");
for ( i = 1; i <= num; i++)
{
document.write (" <br> " + n1);
next_num = n1 + n2;
n1 = n2;
n2 = next_num;
}
</script>
</body>
</html>
List Ways of protecting your web page and describe any one of them.
Ans:
There is nothing secret about your web page. Anyone with a little
computer knowledge can use a few
mouse clicks to display your HTML code, including your JavaScript, on the
screen.
<html>
<head>
<script>
window.onload = function()
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
{
document.addEventListener("contextmenu", function(e)
{
e.preventDefault();
}, false);}
</script>
<body>
<h3>Right click on screen,Context Menu is disabled</h3>
</body>
</html>
webpage.html
<html>
<head>
<script src="mycode.js" languages="javascript" type="text/javascript">
</script>
<body>
<h3> Right Click on screen, Context Menu is disabled</h3>
</body>
</html>
mycode.js
window.onload=function()
Examination Paper Analysis
{
document.addEventListener("contextmenu", function(e)
{
e.preventDefault();
}, false);
}
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
3) Concealing Your E-mail Address
• To conceal an e-mail address, you need to create strings that contain
part of the
e-mail address and then build a JavaScript that assembles those strings
into the e-mail address,
which is then written to the web page.
• The following example illustrates one of many ways to conceal an e-mail
address.
• It also shows you how to write the subject line of the e-mail. We begin by
creating four strings:
• The first string contains the addressee and the domain along with
symbols
&, *, and _ (underscore) to confuse the bot.
• The second and third strings contain portions of the mailto: attribute
name.
Remember that the bot is likely looking for mailto:
• The fourth string contains the subject line. As you'll recall from your
HTML
training, you can generate the TO, CC, BCC, subject, and body
of an e-mail from
within a web page.
• You then use these four strings to build the e-mail address. This process
starts by using the
replace() method of the string object to replace the & with the @ sign and
the * with a period (.).
The underscores are replaced with nothing, which is the same as simply
removing the underscores
from the string.
<html>
<head>
<title>Conceal Email Address</title>
<script>
function CreateEmailAddress()
{
Examination Paper Analysis
var x = 'abcxyz*c_o_m'
var y = 'mai'
var z = 'lto'
var s = '?subject=Customer Inquiry'
x = x.replace('&','@')
x = x.replace('*','.')
x = x.replace('_','')
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
x = x.replace('_','')
var b = y + z +':'+ x + s
window.location=b;
}
</script>
</head>
<body>
<input type="button" value="send" onclick="CreateEmailAddress()">
</body>
</html>
8. Create a slideshow with the group of three images, also simulate next and
previous transition between slides in your Java Script
Ans:
<html>
<head> <script>
pics = new Array('1.jpg' , '2.jpg' , '3.jpg');
count = 0;
function slideshow(status)
{
if (document.images)
{
count = count + status;
if (count > (pics.length - 1))
{
count = 0;
}
if (count < 0)
{
count = pics.length - 1;
}
documet.imag1.src = pics[count];
}}
</script>
</head>
<body>
<img src="1.jpg" width="200" name="img1">
<br>
<input type="button" value="Next" onclick="slideshow(1)">
<input type="button" value="Back" onclick="slideshow(-1)">
</body>
</html>
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
You create a rollover for text by using the onmouseover attribute of the <A>
tag ,which is the anchor tag. You assign the action to the onmouseover
attribute the same way as you do with an <IMG> tag.
Let's start a rollover project that displays a flower titles. Additional information
about a flower can be displayed when the user rolls the mouse cursor over
the flower name. In this example, the image of the flower is displayed.
However, you could replace the flower image with an advertisement or
another message that you want to show about the flower.
<html>
<head>
<title>Rollover Text</title>
</head>
<body>
<TABLE width="100%" border="0">
<TBODY>
<TR vAlign="top">
<TD width="50">
<a>
<IMG height="92" src="rose.jpg" width="70" border="0" name="cover">
</a>
</TD>
<TD>
<IMG height="1" src="" width="10">
</TD>
<TD>
<A onmouseover= "document.cover.src='sunflower.jpg'">
<B><U>Sunflower</U></B>
</A>
<BR>
<A onmouseover=
"document.cover.src='jasmine.jpg'">
<B><U>Jasmine</U></B>
</A>
<BR>
<A onmouseover="document.cover.src='rose.jpg'">
<B><U>Rose</U></B>
</A>
</TD>
</TR>
</TBODY>
</TABLE>
</body>
</html>
10. Write a javascript to create option list containing list of images and then
display images in new window as per selection.
<!DOCTYPE html>
<html lang="en">
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Image Selection</title>
<style>
body {
font-family: Arial, sans-serif;
}
select {
padding: 10px;
margin: 20px;
}
</style>
</head>
<body>
<h1>Select an image to view:</h1>
<!-- Dropdown menu to select image -->
<select id="imageSelect" onchange="openImageWindow()">
<option value="">--Select Image--</option>
<option
value="https://via.placeholder.com/150/0000FF/808080?text=Image+1">I
mage 1</option>
<option
value="https://via.placeholder.com/150/FF5733/FFFFFF?text=Image+2">I
mage 2</option>
<option
value="https://via.placeholder.com/150/32CD32/FFFFFF?text=Image+3">
Image 3</option>
<option
value="https://via.placeholder.com/150/FFD700/FFFFFF?text=Image+4">I
mage 4</option>
</select>
<script>
// Function to open the selected image in a new window
function openImageWindow() {
var imageUrl = document.getElementById('imageSelect').value;
if (imageUrl) {
// Open new window with the image
var imageWindow = window.open("", "_blank", "width=500,
height=500");
imageWindow.document.write("<img src='" + imageUrl + "'
alt='Selected Image' style='width: 100%; height: auto;'>");
}
}
</script>
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
</body>
</html>
12.Write a JavaScript function to merge two array & removes all duplicate
values.
Ans:
<html>
<body>
<script>
function mergearr(arr1, arr2)
{
// merge two arrays
var arr = arr1.concat(arr2);
13.Write HTML script that will display dropdown list containing options such
as Red, Green, Blue and Yellow. Write a JavaScript program such that
when the user selects any options. It will change the background colour of
webpage.
Ans:
<html>
<body>
<label for="color">Choose a Background Color:</label>
<select name="color" id="color" class="color" onchange="changeColor()">
<option value="red">Red</option>
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
<option value="green">Green</option>
<option value="blue">Blue</option>
<option value="yellow">Yellow</option>
</select>
<script type="text/javascript"> function changeColor() {
var color = document.getElementById("color").value;
switch(color){
case "green":
document.body.style.backgroundColor = "green";
break;
case "red":
document.body.style.backgroundColor = "red"; break;
case "blue":
document.body.style.backgroundColor = "blue"; break;
case "yellow":
document.body.style.backgroundColor = "yellow"; break;
default:
document.body.style.backgroundColor = "white"; break;
}
}
</script>
</body>
</html>
Fy-Dip [LIVE] (Sem 2) : 4999/- BUY NOW | Sy-Dip [LIVE] (Sem 3 + 4) : 4999/- BUY NOW
Ty-Dip [LIVE] (Sem 3 + 4) : 4999/- BUY NOW | APP Free Content : CHECK NOW
YOUTUBE : CHECK NOW INSTA : FOLLOW NOW | Contact No : 9326050669 /93268814281
SY DIP WHATSAPP Group : JOIN GROUP 1 JOIN GROUP 2 | ALL FREE CONTENT : CHECK NOW
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
Example:
<html>
<body>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script> function
myFunction()
{
var str = "100, 1000 or 10000?";
var patt1 = /\d{3,4}/g;
var result = str.match(patt1);
document.getElementById("demo").innerHTML = result;
}
</script>
</body>
</html>
Metacharacters
The following table lists a set of metacharacters which can be used in PERL Style
Regular Expressions.
Sr.No. Character & Description
. (dot)
1
a single character
\s
2
a whitespace character (space, tab, newline)
\S
3
non-whitespace character
\d
4
a digit (0-9)
\D
5
a non-digit
\w
6
a word character (a-z, A-Z, 0-9, _)
\W
7
a non-word character
[\b]
8
a literal backspace (special case).
[aeiou]
9
matches a single character in the given set
[^aeiou]
10
matches a single character outside the given set
(foo|bar|baz)
11
matches any of the alternatives specified
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
14. Describe frameworks of JavaScript & its application.
Ans:
Frameworks of JavaScript:
1. ReactJs
React is based on a reusable component. Simply put, these are code blocks
that can be
classified as either classes or functions. Each component represents a
specific part of a
page, such as a logo, a button, or an input box. The parameters they use are
called props, which stands for properties.
Applications:
React is a JavaScript library developed by Facebook which, among other
things, was used to build Instagram.com.
2. Angular
Google operates this framework and is designed to use it to develop a Single
Page
Application (SPA). This development framework is known primarily because it
gives
developers the best conditions to combine JavaScript with HTML and CSS.
Google
operates this framework and is designed to use it to develop a Single Page
Application
(SPA). This development framework is known primarily because it gives
developers the best conditions to combine JavaScript with HTML and CSS.
Applications:
Microsoft Office ,Gmail, Forbes, PayPal, Grasshopper, Samsung, Delta
3. Vue.js
Vue is an open-source JavaScript framework for creating a creative UI. The
integration
with Vue in projects using other JavaScript libraries is simplified because it is
designed to be adaptable.
Application:
VueJS is primarily used to build web interfaces and one-page applications. It
can also be applied to both desktop and mobile app development.
4. jQuery
It is a cross-platform JavaScript library designed to simplify HTML client-side
scripting.
You can use the jQuery API to handle, animate, and manipulate an event in
an HTML
document, also known as DOM. Also, jQuery is used with Angular and React
App building
tools.
Applications:
1. JQuery can be used to develop Ajax based applications.
2. It can be used to make code simple, concise and reusable.
3. It simplifies the process of traversal of HTML DOM tree.
4. It can also handle events, perform animation and add ajax support in web
applications
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
5. Node.js
Node.js is an open-source, server-side platform built on the Google Chrome
JavaScript
Engine. Node.js is an asynchronous, single-threaded, non-blocking I/O model
that makes it lightweight and efficient.
Applications:
Paypal, LinkedIn, Yahoo, Mozilla, Netflix, Uber, Groupon, GoDaddy, eBay
15. Develop a JavaScript program to create Rotating Banner Ads with URL.
Ans
<html > <head>
<title>Banner Ads</title>
<script>
Banners = new Array('1.jpg','2.jpg','3.jpg');
CurrentBanner = 0;
function DisplayBanners()
{
if (document.images);
{
CurrentBanner++;
if (CurrentBanner == Banners.length)
{
CurrentBanner = 0;
}
document.RotateBanner.src= Banners[CurrentBanner];
setTimeout("DisplayBanners()",1000);
}}
</script>
</head>
<body onload="DisplayBanners()" >
<img src="1.jpg" width="400" height="75" name="RotateBanner" />
</body>
</html>
16. How to read, write and delete cookie in javascript? Explain with example.
Ans:
Read a Cookie with JavaScript
With JavaScript, cookies can be read like this: var x = document.cookie;
Write a Cookie with JavaScript
You can access the cookie like this which will return all the cookies saved for the
current domain. document.cookie=x;
Example:
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
<html>
<head> <script> function writeCookie()
{ with(document.myform)
{ document.cookie="Name=" + person.value + ";" alert("Cookie written");
}
} function readCookie()
{ var x; if(document.cookie=="") x=""; else x=document.cookie;
document.write(x);
}
</script>
</head>
<body>
<form name="myform" action="">
<html>
<head> <script>
function writeCookie()
{
var d=new Date();
d.setTime(d.getTime()+(1000*60*60*24));
with(document.myform)
{
document.cookie="Name=" + person.value + ";expires="
+d.toGMTString();
}
}
function readCookie()
{
if(document.cookie=="")
document.write("cookies not found");
else
document.write(document.cookie);
}
</script>
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
</head>
<body>
<form name="myform" action="">
Enter your name:
<input type="text" name="person"><br>
<input type="Reset" value="Set" type="button" onclick="writeCookie()">
<input type="Reset" value="Get" type="button" onclick="readCookie()">
</form>
</body>
</html>
<html>
<head>
<title>JavaScript Status Bar</title></head>
<body>
<a href="http://www.v2v.edu.in" onMouseOver="window.status='Vision to
Victroy';return true" onMouseOut="window.status='';return true">
Vision 2 Victory
</a>
</body>
</html>
18. What is context menu? How to create it? Explain with example.
Ans:
When we click the right mouse button on our desktop, a menu-like box
appears and this box is called the context menu. In JavaScript, a context
menu event runs when a user tries to open a context menu. This can be done
by clicking the right mouse button.
Example:
<html>
<head>
<style>
div {
background: yellow;
border: 1px solid black;
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
padding: 10px;
}
</style>
</head>
<body>
<div contextmenu="mymenu">
</div>
</body>
</html>
19. Write a javascript program to validate emailID, pincode, phone of the user
using regular expression.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Validation Example</title>
</head>
<body>
<h2>Validation Form</h2>
<form id="validationForm">
Email:<input type="text" id="email"><br><br>
Name:<input type="text" id="name"><br><br>
Aadhaar Number:<input type="text" id="aadhaar"><br><br>
IP Address:<input type="text" id="ip"><br><br>
Phone Number:<input type="text" id="phone"><br><br>
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
Pincode:<input type="text" id="pincode"><br><br>
<button type="button" onclick="validateForm()">Validate</button>
</form>
<script>
function validateForm() {
var email = document.getElementById("email").value;
var name = document.getElementById("name").value;
var aadhaar = document.getElementById("aadhaar").value;
var ip = document.getElementById("ip").value;
var phone = document.getElementById("phone").value;
var pincode = document.getElementById("pincode").value;
if (!emailPattern.test(email)) {
alert("Invalid email ID");
} else if (!namePattern.test(name)) {
alert("Invalid name");
} else if (!aadhaarPattern.test(aadhaar)) {
alert("Invalid Aadhaar number");
} else if (!ipPattern.test(ip)) {
alert("Invalid IP address");
} else if (!phonePattern.test(phone)) {
alert("Invalid phone number");
} else if (!pincodePattern.test(pincode)) {
alert("Invalid pincode");
} else {
alert("All inputs are valid");
}
}
</script>
</body>
</html>
20. 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
option list should present only fruits names to the user & when user select
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
vegetable radio button option list should present only vegetable names to
the user.
Ans:
<head>
<title>HTML Form</title>
<script language="javascript" type="text/javascript"> 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>
<form name="myform" action="" method="post">
<p>
<select name="optionList" size="2">
<option value=1>Mango
<option value=2>Banana
<option value=3>Apple
</select>
<br>
<input type="radio" name="grp1" value=1 checked="true"
onclick="updateList(this.value)">Fruits <input type="radio" name="grp1"
value=2 onclick="updateList(this.value)">Vegetables
<br>
<input name="Reset" value="Reset" type="reset">
</p>
</form>
</body>
</html>
21. Write a script for creating following frame structure FRUITS, FLOWERS
AND CITIES are links to the webpage fruits.html, flowers.html, cities.html
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
respectively. When these links are clicked corresponding data appears in
FRAME 3.
Ans:
<html>
<head>
<title>Frame Demo</title>
</head>
<body>
<table border="1">
<tr>
<td align="center" colspan="2">
FRAME 1
</td>
</tr>
<tr>
<td>
FRAME 2
<ul>
<li>
<a href="fruits.html" target="mainframe">FRUITS</a>
</li>
<li>
<a href="flowers.html" target="mainframe">FLOWERS</a>
</li>
<li>
<a href="cities.html" target="mainframe">CITIES</a>
</li>
</ul>
</td>
<td>
FRAME 3<BR>
<iframe name="mainframe"></iframe>
</td>
</tr>
</table> </body>
</html>
22. Write a javascript to create a pull-down menu with three options [Google,
MSBTE, Yahoo] once the user will select one of the options then user will
be redirected to that site.
Ans:
<head>
<title>HTML Form</title>
<script language="javascript" type="text/javascript">
function getPage(choice)
{
page=choice.options[choice.selectedIndex].value; if(page != "")
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
{
window.location=page;
}}
</script>
</head>
<body>
<form name="myform" action="" method="post"> Select Your Favourite
Website:
<select name="MenuChoice" onchange="getPage(this)">
<option
value="https://www.google.com">Google</option>
<option
value="https://www.msbte.org.in">MSBTE</option>
<option
value="https://www.yahoo.com">Yahoo</option>
</form>
</body>
</html>
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
<ul class="nested">
<li>Mumbai</li>
<li>Pune</li>
<li><span class="caret">Navi Mumbai</span>
<ul class="nested">
<li>Nerul</li>
<li>Vashi</li>
<li>Panvel</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<script>
var toggler = document.getElementsByClassName("caret"); var i;
for (i = 0; i < toggler.length; i++) {
toggler[i].addEventListener("click", function() {
this.parentElement.querySelector(".nested").classList.toggle("active");
this.classList.toggle("caret-down");
});
}
</script>
</body>
</html>
if(string == reverseString) {
document.write('It is a palindrome');
}
else {
document.write('It is not a palindrome');
}
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
25. Write JavaScript to create object “student”with properties roll number ,name,branch,year,Delete
branch property and display remaining properties of student object.
Ans:
<script>
var student ={
roll_number:1001
branch:”IF”
year:First
2M
Proper
correct
logic
progra
m2
marks
name:”XYZ”
document.write(student.roll_number+” ”+student.branch+” “ +
student.year+” “ +student.name);
delete student.branch;
document.write(student.roll_number+” ”+student.branch+” “ +
student.year+” “ +student.name);
</script>
26.Write a JavaScript for loop that will iterate from 1 to 15. For each iteration it will check if
the
current number is obb or even and display a message to the screen
Sample Output:
“1 is odd”
“2 is even”
….............
…....
Ans:
<script>
for(var i=1; i<=15; i++)
{
if(i%2)
{
document.write(i+”is even”);
}
else
{
document.write(i+”is odd”);
}
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
}
</script>
2
Fy-Dip [LIVE] (Sem 2) : 4999/- BUY NOW | Sy-Dip [LIVE] (Sem 3 + 4) : 4999/- BUY NOW
Ty-Dip [LIVE] (Sem 3 + 4) : 4999/- BUY NOW | APP Free Content : CHECK NOW
YOUTUBE : CHECK NOW INSTA : FOLLOW NOW | Contact No : 9326050669 /93268814282
SY DIP WHATSAPP Group : JOIN GROUP 1 JOIN GROUP 2 | ALL FREE CONTENT : CHECK NOW
<html>
<body>
<script>
const number1 = parseFloat(prompt("Enter first number: "));
const number2 = parseFloat(prompt("Enter second number: "));
const operator = prompt("Enter operator ( either +, -, *, / or %): ");
let result;
switch (operator) {
case "+":
result = number1 + number2;
document.write(result);
break;
case "-":
result = number1 - number2;
document.write(result);
break;
case "*":
result = number1 * number2;
document.write(result);
break;
case "/":
result = number1 / number2;
document.write(result);
break;
case "%":
result = number1 % number2;
document.write(result);
break;
default:
document.write("Invalid operator");
break;
}
</script>
</body>
</html>
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
28.Write a JavaScript program to check whether entered number is prime or not.
Ans:
<html>
<body>
<script>
var i, chk=0;
var num = prompt("Enter a positive number: "));
for(i=2; i<num; i++)
{
if(num%2==0)
{
chk++;
break;
}
}
if(chk==0)
document.write(num + " is a Prime Number");
else
document.write(num + " is not a Prime Number");
</script>
</body>
</html>
Ans:
<script>
// program to check if the string is palindrome or not
function checkPalindrome(string)
{
// convert string to an array
const arrayValues = string.split('');
if(string == reverseString) {
document.write('It is a palindrome');
}
else {
document.write('It is not a palindrome');
}
}
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
//take input
const string = prompt('Enter a string: ');
checkPalindrome(string);
</script>
30. Write a JavaScript program to validate user accounts for multiple set of user
ID and password (using switch case statement).
Ans:
<html>
<body>
Enter your User ID
<input type="text" id="id">
<br><br>
Enter your Password
<input type="password" id="pass">
<br><br>
<input type="submit" onclick="check()">
<br><br>
<p id="display"></p>
<script>
function check() {
var uid = document.getElementById('id').value;
var pass = document.getElementById('pass').value;
switch(uid){
case "darshan.khapekar@vpt.edu.in":
if(pass == "darshan@123"){
document.getElementById('display').innerHTML = "Valid User";
}
break;
case "prashant.yelurkar@vpt.edu.in":
if(pass == "prashant@123"){
document.getElementById('display').innerHTML = "Valid User";
}
break;
case "konisha.thakare@vpt.edu.in":
if(pass == "konisha@123"){
document.getElementById('display').innerHTML = "Valid User";
}
break;
default:
document.getElementById('display').innerHTML = "Invalid User";
}
}
</script>
</body>
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
</html>
31.Write the use of charCodeAt() and fromCharCode() method with syntax and
example
Ans:
charChodeAt():
• The charCodeAt() method takes an integer as an argument that represents the
index of the character
in which you’re interested. If you don’t pass an argument, it defaults to index 0.
• The charCodeAt() method returns the Unicode number of the string:
var UnicodeNum = StringName.charCodeAt()
Example:
<script>
var x="Javatpoint";
document.writeln(x.charCodeAt(3));
</script>
fromCharCode():
• If you need to know the character, number, or symbol that is assigned to a Unicode
number, use the
fromCharCode() method. The fromCharCode() method requires one argument,
which is the Unicode
number.
Example:
<html>
<body>
<script>
document.write("<br>"+res1);
</script>
</body>
</html>
Ans:
<script>
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
Var str=” Sudha Narayana Murth”
Var arr=str.spilt(“ “,3);
document.write(“First Name:+arr[0]+”<br”>
document.write(“Middle Name:+arr[1]+”<br”>
document.write(“Last Name:+arr[1]+”<br”>
</script>
Ans:
<script>
Var str=” Sudha Narayana Murth”
Var arr=str.spilt(“ “,3);
document.write(“First Name:+arr[0]+”<br”>
document.write(“Middle Name:+arr[1]+”<br”>
document.write(“Last Name:+arr[1]+”<br”>
</script>
<!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>
<script>
var d=new Date();
var currentDate=d.getDate()+'/'+(d.getMonth()+1)+'/'+d.getFullYear()
document.write(currentDate)
</script>
</body>
</html>
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
34.Write HTML code to design a form that dsiplayes two buttons START and
STOP.Write a JavaScript code
such that when user clicks on START button, real time digital clock will be displayed
on screen. When user
clicks on STOP button,clock will stop displaying time(Use Timer Methods)
Ans:
<html>
<body>
<p>A script on this page starts this clock:</p>
<p id="demo"></p>
<button onclick="clearInterval(myVar)">Stop time</button>
<script>
var myVar = setInterval(myTimer ,1000);
function myTimer()
{
var d = new Date();
document.getElementById("demo").innerHTML = d.toLocaleTimeString();
}
</script>
</body>
</html>
35.Enlist & explain the use of any two Intrinsic JavaScript functions.
Ans:
An intrinsic function (or built-in function) is a function (subroutine) available for use in
a given programming
language whose implementation is handled specially by the compiler. You can use
intrinsic functions to make
reference to a data item whose value is derived automatically during execution.
abs() - The ABS function returns the absolute value of the argument.
sin() - The SIN function returns a numeric value that approximates the sine of the
angle or arc specified by the
argument in radians.
sqrt() - The SQRT function returns a numeric value that approximates the square
root of the argument
specified.
Date(): return current date.
Len(): returns number of characters in the text.
parseInt() - parseInt() function takes string as a parameter and converts it to integer.
parseFloat() - parseFloat() function takes a string as parameter and parses it to a
floating point number.
36.Enlist & explain the use of any two Intrinsic JavaScript functions.
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
Ans:
An intrinsic function (or built-in function) is a function (subroutine) available for use in
a given programming
language whose implementation is handled specially by the compiler. You can use
intrinsic functions to make
reference to a data item whose value is derived automatically during execution.
abs() - The ABS function returns the absolute value of the argument.
sin() - The SIN function returns a numeric value that approximates the sine of the
angle or arc specified by the
argument in radians.
sqrt() - The SQRT function returns a numeric value that approximates the square
root of the argument
specified.
Date(): return current date.
Len(): returns number of characters in the text.
parseInt() - parseInt() function takes string as a parameter and converts it to integer.
parseFloat() - parseFloat() function takes a string as parameter and parses it to a
floating point number.
Text rollover:
We can also create a rollover and rollback for text using the onmouseover and
onmouseout.
Ans:
<html>
<head>
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
<title>
text rollovers</title>
</head>
<body>
<table border="1" width="100%">
<tbody>
<tr valign="top">
<td width="50%">
<a><img height="500" src="blue.png" width="900" name="clr"></a></td>
<td><a onmouseover="document.clr.src='blue.png' ">
<b><u> Blue Color</u></b></a> 55
<br>
<a onmouseover="document.clr.src='red.png' ">
<b><u> Red Color</u></b></a>
<br>
<a onmouseover="document.clr.src='green.png' ">
<b><u> Green Color</u></b></a>
</td>
</tr>
</tbody>
</table>
</body>
</html>
Image Rollover:
<html>
<head>
<title>JavaScript Image Rollovers</title>
</head>
<body>
<img src="blue.png" name="image1" onmouseover="src='car.jpg' "
onmouseout="src='blue.png' ">
</img>
</body>
</html>
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material