0% found this document useful (0 votes)
4 views

css micro

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

css micro

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

Q1.

State the use of dot syntax in JavaScript with the help of


suitable example.
In JavaScript, dot syntax is used to access properties and
methods of an object. It allows you to specify the object
followed by a dot (.) and the name of the property or method you
want to access.
Here's an example to illustrate the use of dot syntax in
JavaScript:
// Creating an object
var person = {
name: 'John',
age: 30,
greet: function() {
console.log('Hello, my name is ' + this.name + ' and I am ' +
this.age + ' years old.');
}
};
// Accessing properties using dot syntax
console.log(person.name); // Output: John
console.log(person.age); // Output: 30
// Calling a method using dot syntax
person.greet(); // Output: Hello, my name is John and I am 30
years old.
Q2. explain the use of any two Intrinsic JavaScript functions.
Sure! I'll explain the use of two intrinsic JavaScript functions:
parseInt() and setTimeout()
1. parseInt(): The parseInt() function is used to parse a string
and convert it into an integer. It takes two arguments: the
string to be parsed and an optional radix (base) specifying
the numeral system to be used (e.g., base 10, base 16, etc.). If
the radix is not specified, parseInt() assumes base 10.
Here's an example:
var numberString = "42";
var parsedNumber = parseInt(numberString);
console.log(parsedNumber); // Output: 42
console.log(typeof parsedNumber); // Output: number
In the example above, parseInt(numberString) converts the string
"42" into the number 42. The parsed number is then assigned to
the parsedNumber variable. The console.log() statements show
the parsed number and its type.
2. 'setTimeout()': The 'setTimeout()' function is used to
schedule the execution of a function after a specified delay in
milliseconds. It takes two arguments: a function to be
executed and the delay in milliseconds.
Here's an example:
function greet() {
console.log("Hello, world!");
}
setTimeout(greet, 2000); // Executes the greet function after
a 2-second delay
In the example above, the greet() function will be executed after
a 2-second delay. The setTimeout() function schedules the
execution of the greet function. The delay is specified as 2000 (2
seconds) in this case.
Q3. Explain javascript intrinsic functions
Intrinsic functions, also known as built-in functions, are
predefined functions provided by the JavaScript programming
language. These functions are part of the JavaScript language
specification and are available for use without the need for any
additional setup or external dependencies.
Intrinsic functions cover a wide range of functionalities, such as
manipulating strings, performing mathematical operations,
working with arrays, interacting with the browser's Document
Object Model (DOM), handling asynchronous operations, and
more. These functions are accessible globally, meaning you can
use them anywhere in your JavaScript code.
Here are a few categories of intrinsic functions in JavaScript:
1) String Functions: These functions allow you to manipulate
and analyze strings. Examples include charAt(), substring(),
indexOf(), toUpperCase(), toLowerCase(), and replace().
2) Math Functions: JavaScript provides various mathematical
functions for performing calculations. Examples include
Math.abs(), Math.floor(), Math.random(), Math.max(),
Math.min(), Math.round(), and Math.pow().
3) Array Functions: These functions help in manipulating and
working with arrays. Examples include Array.push(),
Array.pop(), Array.join(), Array.slice(), Array.concat(),
Array.reverse(), Array.sort(), and Array.indexOf().
4) Date Functions: JavaScript has built-in functions for working
with dates and times. Examples include Date.now(),
Date.getFullYear(), Date.getMonth(), Date.getDate(),
Date.getHours(), Date.getMinutes(), Date.getSeconds(), and
Date.toString().
5) DOM Functions: These functions are used to interact with the
Document Object Model (DOM) in web browsers. Examples
include document.getElementById(),
document.querySelector(), element.addEventListener(),
element.appendChild(), element.setAttribute(), and
element.innerHTML.
6) Asynchronous Functions: JavaScript provides functions for
handling asynchronous operations, such as timers and AJAX
requests. Examples include setTimeout(), setInterval(),
fetch(), and XMLHttpRequest().
Q4. State and explain what is a cookie and its types
with example ?
Cookies are nothing but a small file containing text which is
being made when you enter a website. According to the law, if a
website plans on collecting cookies, it must get consent before
doing so. When a new web page is opened, they're typically
written.
Cookies are tiny text files with a name, value, and attribute that
are often encrypted. A web server's name is used to identify
cookies. Value is a random alphanumeric character that holds
information such as a unique identifier for the user and other
data. The data can be obtained and utilized to customize the web
page once the code has read the cookie on the server or client
computer.
Types of Cookies
Cookies are divided based on their attributes, such as source,
duration, and purpose.
Cookies Based on Source
• First-party cookies − The user's browser sets first-party
cookies when they visit a website. The information gathered
by first-party cookies is used to calculate page views,
sessions, and the number of users. Ad agencies and
advertisers primarily utilize it to locate potential ad targets.
• Third-party cookies − These are set by domains that the
user does not visit directly. This occurs when publishers
include third-party elements on their website (such as a
chatbot, social plugins, or advertisements).
Cookies Based on Duration
• Session cookie − A session cookie is a file that a website
server delivers to a browser with an identification (a string of
letters and numbers) for temporary use during a set period.
By default, session cookies are enabled. Their goal is to make
individual webpages load faster and improve website
navigation.
• Persistent cookies − Persistent cookies are those that remain
in the browser for an extended length of time. They will only
be erased when the cookies expire or the users clear them
from the browser after being installed.
Cookies Based on Purpose
• Necessary cookies − These are cookies that have to be
present for a website to work.
• Non-Necessary cookies − These cookies help keep track of
the behavior on a browser.
Q5. Write a JavaScript function that checks whether a
passed string is palindrome or not
// Write a JavaScript function that checks whether a passed string
is palindrome or not?
function check_Palindrome(str_entry){
// Change the string into lower case and remove all non-
alphanumeric characters
var cstr = str_entry.toLowerCase().replace(/[^a-zA-Z0-
9]+/g,'');
var ccount = 0;
// Check whether the string is empty or not
if(cstr==="") {
console.log("Nothing found!");
return false;
}
// Check if the length of the string is even or odd
if ((cstr.length) % 2 === 0) {
ccount = (cstr.length) / 2;
} else {
// If the length of the string is 1 then it becomes a palindrome
if (cstr.length === 1) {
console.log("Entry is a palindrome.");
return true;
} else {
// If the length of the string is odd ignore middle character
ccount = (cstr.length - 1) / 2;
}}
// Loop through to check the first character to the last character
and then move next
for (var x = 0; x < ccount; x++) {
// Compare characters and drop them if they do not match
if (cstr[x] != cstr.slice(-1-x)[0]) {
console.log("Entry is not a palindrome.");
return false;
}}
console.log("The entry is a palindrome.");
return true; }
check_Palindrome('madam');
check_Palindrome('nursesrun');
check_Palindrome('fox');

Output:
The entry is a palindrome.
The entry is a palindrome.
Entry is not a palindrome.
Q6. Write a JavaScript that find and displays number of
duplicate values in an array.
<!DOCTYPE html>
<html>
<body>
<h3>Finding duplicate values in a JavaScript array</h3>
<p>Here, we will find the repeating values in the given
array.</p>
<p>Original array: [6, 9, 15, 6, 13, 9, 11, 15]</p>
<p id="result"></p>
<script>
//simple traversal method
let array = [6, 9, 15, 6, 13, 9, 11, 15];
let index = 0, newArr = [];
const length = array.length; // to get length of array
function findDuplicates(arr) {
for (let i = 0; i < length - 1; i++) {
for (let j = i + 1; j < length; j++) {
if (arr[i] === arr[j]) {
newArr[index] = arr[i];
index++;
}}}
return newArr;
}
document.getElementById('result').innerHTML = 'Duplicate
values are: <b>' + findDuplicates(array) + '</b>';
</script>
</body>
</html>

Output :
Finding duplicate values in a JavaScript array
Here, we will find the repeating values in the given array.
Original array: [6, 9, 15, 6, 13, 9, 11, 15]
Duplicate values are: 6,9,15
Q7. 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> <meta charset="utf-8">
<title>Change the Background Color with JavaScript</title>
<script>
// Function to change webpage background color
function changeBodyBg(color){
document.body.style.background = color;
}
// Function to change heading background color
function changeHeadingBg(color){
document.getElementById("heading").style.background = color;
}
</script> </head> <body>
<h1 id="heading">This is a heading</h1>
<p>This is a paragraph of text.</p>
<hr> <div>
<label>Change Webpage Background To:</label>
<button type="button"
onclick="changeBodyBg('yellow');">Yellow</button>
<button type="button"
onclick="changeBodyBg('lime');">Lime</button>
<button type="button"
onclick="changeBodyBg('orange');">Orange</button>
</div> <br> <div>
<label>Change Heading Background To:</label>
<button type="button"
onclick="changeHeadingBg('red');">Red</button>
<button type="button"
onclick="changeHeadingBg('green');">Green</button>
<button type="button"
onclick="changeHeadingBg('blue');">Blue</button>
</div>
</body>
</html>
Q8. Develop JavaScript to convert the given character to
Unicode and vice versa.
<html> <head> </head> <body>
<h2>Convert Unicode values to characters in JavaScript.</h2>
<h4>Converting single Decimal Unicode value to character
using the <i> fromCharCode() </i> method.</h4>
<p id = "output"> </p>
<script>
let output = document.getElementById("output");
// converting different decimal values to characters
let value = 69;
let
char = String.fromCharCode( value );
output.innerHTML += value + " to unicode character is : " +
char + " <br/> ";
char = String.fromCharCode( 97 );
output.innerHTML += 97 + " to unicode character is : " + char +
" <br/> ";
</script> </body> </html>
Q9. List ways of Protecting your webpage and describe
any one of them.
At the time of the rapid digital transformation of the global
economy, companies communicate with their clients either
through social media channels or using their websites. By
opening the company’s website users can view all recent
updates, buy products or services, contact the company’s
representatives, get special offers, etc.

When the company’s website is down, it’s experiencing


significant reputational and financial losses. And malicious
actors, as well as unfair competitors, realize it. Hackers target
corporate websites to get a ransom payment or at the request of
competitors. That is why one of the most common questions put
by companies to cybersecurity experts is “how to protect
websites from hackers”.
How to Protect Website
1) Install SSL and Security Plugins
2) Have The Latest Security Software in Place
3) Use Strong Password
4) Use https Protocol
5) Don’t Follow Commands Contained in Suspicious Emails
6) Control What Data Users Upload to Website
7) Use Website Security Tools
8) Back Up Your Website
9) Choose Reputable Web Hosting Providers
10) Use Only Required Plugins
11) Pass Regular Security Testing
Q12. Develop a JavaScript Program to Create Rotating
Banner Ads with URL Links.
<html> <head>
<script language="Javascript">MyBanners=new
Array('banner1.jpg','banner2.jpg','banner3.jpg','banner4.jpg')
MyBannerLinks=new
Array('http://www.vbtutor.net/','http://www.excelvbatutor.com/','
http://onlinebizguide4you.com/','http://javascript-tutor.net/')
banner=0
function ShowLinks(){
document.location.href="http://www."+MyBannerLinks[banner]
}function ShowBanners()
{ if (document.images)
{ banner++
if (banner==MyBanners.length) {
banner=0}
document.ChangeBanner.src=MyBanners[banner]
setTimeout("ShowBanners()",5000)
} } </script>
<body onload="ShowBanners()"> <center>
<a href="javascript: ShowLinks()">
<img src="banner1.jpg" width="900" height="120"
name="ChangeBanner"/></a>
</center> </body> </html>
Q13. Create a slideshow with the group of four images, also
simulate the next and previous transition between slides in
your JavaScript.
<html> <head>
<title>Image SlideShow</title> <script>
var images = ["01.jpg", "02.jpg", "03.jpg", "04.jpg", "05.jpg"];
var count = 0;
function previousImage() {
if(count!=0)
count--;
var id = document.getElementById("imageId");
id.src = "images/" + images[count]; }
function nextImage() {
if(count!=4)
count++;
var id = document.getElementById("imageId");
id.src = "images/" + images[count]; }
</script> </head> <body> <center>
<img id="imageId" src="images/01.jpg" width="300"
height="200"/>
<br/> <hr>
<input type="button" value="< Prev Image"
onclick="previousImage()"/>
<input type="button" value="Next Image >"
onclick="nextImage()"/>
</center> </body> </html>
Q16. Generate college Admission form using html form tag
<Html> <head> <title> Registration Page
</title> </head>
<body bgcolor="Lightskyblue"> <br> <br> <form>
<label> Firstname </label>
<input type="text" name="firstname" size="15"/> <br> <br>
<label> Middlename: </label>
<input type="text" name="middlename" size="15"/> <br> <br>
<label> Lastname: </label>
<input type="text" name="lastname" size="15"/> <br> <br>
<label>
Course :
</label> <select>
<option value="Course">Course</option>
<option value="BCA">BCA</option>
<option value="BBA">BBA</option>
<option value="B.Tech">B.Tech</option>
<option value="MBA">MBA</option>
<option value="MCA">MCA</option>
<option value="M.Tech">M.Tech</option>
</select>
<br> <br> <label>
Gender :
</label><br>
<input type="radio" name="male"/> Male <br>
<input type="radio" name="female"/> Female <br>
<input type="radio" name="other"/> Other
<br> <br> <label>
Phone :
</label>
<input type="text" name="country code" value="+91"
size="2"/>
<input type="text" name="phone" size="10"/> <br> <br>
Address
<br>
<textarea cols="80" rows="5" value="address">
</textarea> <br> <br>
Email:
<input type="email" id="email" name="email"/> <br>
<br> <br>
Password:
<input type="Password" id="pass" name="pass"> <br>
<br> <br>
Re-type password:
<input type="Password" id="repass" name="repass"> <br> <br>
<input type="button" value="Submit"/>
</form> </body> </html>
Q17. Explain prompt() and confirm() method of Java script
with syntax and example.
prompt()
Use the prompt() function to take the user's input to do further
actions. For example, use the prompt() function in the scenario
where you want to calculate EMI based on the user's preferred
loan tenure.
Syntax: string prompt([message], [defaultValue]);
The prompt() function takes two parameters. The first
parameter is the message to be displayed, and the second
parameter is the default value in an input box.
var name = prompt("Enter your name:", "John");
if (name == null || name == "") {
document.getElementById("msg").innerHTML = "You did not
entert anything. Please enter your name again"; }
else { document.getElementById("msg").innerHTML = "You
enterted: " + name; }

confirm()
Use the confirm() function to take the user's confirmation before
starting some task. For example, you want to take the user's
confirmation before saving, updating or deleting data.
Syntax: bool window.confirm([message]);
The confirm() function displays a popup message to the user
with two buttons, OK and Cancel. The confirm() function returns
true if a user has clicked on the OK button or returns false if
clicked on the Cancel button. You can use the return value to
process further.
var userPreference;
if (confirm("Do you want to save changes?") == true) {
userPreference = "Data saved successfully!";
} else {userPreference = "Save Cancelled!";}

Q 15. Define window & frame.


Frame windows are windows that frame an application or a part
of an application. Frame windows usually contain other
windows, such as views, tool bars, and status bars. In the case of
CMDIFrameWnd , they may contain CMDIChildWnd objects
indirectly. CFrameWnd. The base class for an SDI application's
main frame window.
Q18. Describe regular expression
A regular expression is a sequence of characters that forms
a search pattern. When you search for data in a text, you can
use this search pattern to describe what you are searching for. A
regular expression can be a single character, or a more
complicated pattern. Regular expressions can be used to perform
all types of text search and text replace operations.
Syntax: /pattern/modifiers;
Example: /w3schools/i;
Example explained:
/w3schools/i is a regular expression.
w3schools is a pattern (to be used in a search).
i is a modifier (modifies the search to be case-insensitive).
Using String Methods
• In JavaScript, regular expressions are often used with the
two string methods: search() and replace().
• The search() method uses an expression to search for a
match, and returns the position of the match.
• The replace() method returns a modified string where the
pattern is replaced.
Using String search() With a String: The search() method
searches a string for a specified value and returns the position of
the match:
Example Use a string to do a search for "W3schools" in a string:
let text = "Visit W3Schools!";
let n = text.search("W3Schools");
The result in n will be: 6
Q19. Explain text rollover with suitable example.
In this lesson, we shall learn how to create the rollover effect in
JavaScript. Rollover means a webpage changes when the user
moves his or her mouse over an object on the page. It is often
used in advertising.There are two ways to create rollover, using
plain HTML or using a mixture of JavaScript and HTML. We
will demonstrate the creation of rollovers using both methods.
Creating Rollovers using HTML
The keyword that is used to create rollover is the <onmousover>
event. For example, we want to create a rollover text that appears
in a text area. The text “What is rollover?” appears when the
user place his or her mouse over the text area and the rollover
text changes to “Rollover means a webpage changes when the
user moves his or her mouse over an object on the page” when
the user moves his or her mouse away from the text area.
Text rollover, also known as a hover effect, refers to the behavior
where an element, such as text, changes its appearance when the
mouse pointer is positioned over it. In JavaScript, this effect can
be achieved by using event listeners to detect when the mouse
enters or leaves the element and manipulating its style or content
accordingly.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
.rollover {
font-size: 20px;
color: blue;
}
.rollover:hover {
color: red;
font-weight: bold;
}
</style>
</head>
<body>
<p class="rollover">Hover over this text to see the effect!</p>
<script src="script.js"></script>
</body>
</html>

Q 17. Write a Java Script code to display 5 elements of array


in sorted order.

<html> <head>
<title> Array</title>
</head> <body> <script>
var arr1 = [ “Red”, “red”, “Blue”, “Green”]
document.write(“Before sorting arra1=” + arr1);
document.write(“<br>After sorting arra1=” + arr1.sort());
</script> </body> </html>
Q15. Write a script for creating following frame structure :
Fruits, Flowers and Cities are links to the webpage
fruits.html, flowers.html, cities.html respectively. When these
links are clicked corresponding data appears in “FRAME3”.
<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>
Q 1. What do you mean by scripting language ? Give one
example.
Script is a small piece of program that can add interactivity to
the website
Scripting language is a form of programming language that is
usually interpreted rather than compiled.
There are 2 types of scripting language.
1. Client Side scripting language -- eg javascript, VBscript
2. Server side scripting language – JSP,ASP,PHP
Q 2. List out any 6 features of java script.
• Scripting Language. JavaScript is a lightweight scripting
language made for client-side execution on the browser. ...
• Interpreter Based.
• Event Handling.
• Light Weight.
• Case Sensitive.
• Control Statements.
• Objects as first-class citizens.

Q 10. List out any 4 methods for string class.


• JavaScript String Length. The length property returns the
length of a string: ...
• JavaScript String slice() ...
• JavaScript String substring() ...
• JavaScript String substr() ...
• Replacing String Content. ...
• JavaScript String ReplaceAll() ...
• JavaScript String toUpperCase() ...
Q 6. Write a program to take the input from user using
prompt box.
1. <html>
2. <head>
3. <script type = "text/javascript">
4. function fun() {
5. prompt ("This is a prompt box", "Hello world");
6. }
7. </script>
8. </head>
9.
10. <body>
11. <p> Click the following button to see the effect </p>
12. <form>
13. <input type = "button" value = "Click me" onclick = "f
un();" />
14. </form>
15. </body>
16. </html>
Q 6. Write a program to check whether a number is prime or
not by taking input from user.
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Check a number is prime or not</title>
</head>
<body>
</body>
</html>
Q 8. How to sort the array.
You can use the JavaScript sort() method to sort an array. The
sort() method accepts an array as an argument and sorts its
values in ascending order. Arrays are sorted in place which
means the original array is modified.
Introduction to JavaScript Array sort() method
The sort() method allows you to sort elements of an array in
place. Besides returning the sorted array, the sort() method
changes the positions of the elements in the original array.
By default, the sort() method sorts the array elements in
ascending order with the smallest value first and largest value
last.
Q10. State use of getters and setters
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
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.
If property has only a setter method , it is a write-only
property.
6. getter works when obj.propName is read, the setter – when it
is assigned.
Example:
<html> <head>
<title>Functions</title>
<body>
<script language="Javascript">
var myCar = {
/* Data properties */
defColor: "blue",
defMake: "Toyota",
/* Accessor properties (getters) */
get color() {
return this.defColor; },
get make() {
return this.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>Car color:" + myCar.color); // red
document.write(" Car Make: "+myCar.make); //Audi
</script>
</head>
</body> </html>
Q 7. Define variables and keywords with example.
Variables : Always declare JavaScript variables with var , let , or
const . The var keyword is used in all JavaScript code from 1995
to 2015. The let and const keywords were added to JavaScript in
2015. If you want your code to run in older browsers, you must
use var .
Keywords: var is the keyword that tells JavaScript you're
declaring a variable. x is the name of that variable. = is the
operator that tells JavaScript a value is coming up next.
In this example, x, y, and z, are variables, declared with
the var keyword:
var x = 5; var y = 6; var z = x + y;
Q 8. How to sort the array.
You can use the JavaScript sort() method to sort an array. The
sort() method accepts an array as an argument and sorts its
values in ascending order. Arrays are sorted in place which
means the original array is modified.
Introduction to JavaScript Array sort() method
The sort() method allows you to sort elements of an array in
place. Besides returning the sorted array, the sort() method
changes the positions of the elements in the original array.
By default, the sort() method sorts the array elements in
ascending order with the smallest value first and largest value
last.
Q11. State the use of following methods.
i. charCodeAt()
The method charCodeAt() allows us to get the Unicode value of
characters inside a string. Every character has its own specific
Unicode. For example, the letter H has a Unicode value of 72.
The method accepts one argument(index of the character) and
returns the Unicode value of the character in the string. In
addition to that, the method charCodeAt() is supported in all the
browsers which is good.
Have a look at the example below:
let ourSentence = "JavaScript is super awesome";
//get the Unicode of the first character(J).
ourSentence.charCodeAt(0); //returns 74
//the Unicode of the second character(a).
ourSentence.charCodeAt(1); //97
//get the Unicode of the last character(e).
ourSentence.charCodeAt(ourSentence.length - 1); //returns 101

ii. fromCharCode()
The method fromCharCode allows us to easily convert any
Unicode value into a character. It's the opposite of the method
charCodeAt().
The method accepts one required argument(the Unicode value)
and you can also pass multiple Unicodes if you want to make a
word or a sentence.
The method is accessed through the object String with dot
notation.
Here is the example:
String.fromCharCode(74); //returns "J"
String.fromCharCode(118); //returns "v"
//multiple arguments.
String.fromCharCode(74, 65, 118, 65); //returns "JAvA"

Q 12. What is the difference between text field and text area.
Give its syntax.
JTextField
• A JTextFeld is one of the most important components
that allow the user to an input text value in a single line
format.
• A JTextField will generate an ActionListener interface
when we trying to enter some input inside it.
• The JTextComponent is a superclass
of JTextField that provides a common set of methods
used by JTextfield.
• The important methods in the JTextField class
are setText(), getText(), setEnabled(), etc.
JTextArea
• A JTextArea is a multi-line text component to display
text or allow the user to enter text.
• A JTextArea will generate a CaretListener interface.
• The JTextComponent is a superclass of JTextArea that
provides a common set of methods used by JTextArea.
• The important methods in the JTextArea class
are setText(), append(), setLineWrap(),
setWrapStyleWord(), setCaretPosition(), etc.
Q 13. What do you mean by intrinsic function ?
An intrinsic function is a function that performs a mathematical,
character, or logical operation. You can use intrinsic functions to
make reference to a data item whose value is derived
automatically during execution.
Data processing problems often require the use of values that are
not directly accessible in the data storage associated with the
object program, but instead must be derived through performing
operations on other data. An intrinsic function is a function that
performs a mathematical, character, or logical operation, and
thereby allows you to make reference to a data item whose value
is derived automatically during execution.
The intrinsic functions can be grouped into six categories, based
on the type of service performed:
• Mathematical
• Statistical
• Date/time
• Financial
• Character-handling
• General
You can reference a function by specifying its name, along with
any required arguments, in a PROCEDURE DIVISION
statement.
Functions are elementary data items, and return alphanumeric
character, national character, numeric, or integer values.
Functions cannot serve as receiving operands.
Q3. Write a program for switch case statement in java script
to print months .
<html>
<script language="JavaScript">
<!--
function getMonthString(num)
{
var month; //Create a local variable to hold the string
switch(num)
{
case 0: month="January"; break; case 1: month="February"; break;
case 2: month="March"; break; case 3: month="April"; break;
case 4: month="May"; break; case 5: month="June"; break;
case 6: month="July"; break; case 7: month="August"; break;
case 8: month="September"; break; case 9: month="October"; break;
case 10: month="November"; break; case 11: month="December"; bre
ak;
default: month="Invalid month";
} return month;
}
theDate = new Date();
document.write("The month is ",getMonthString(theDate.get
Month()));
-->
</script> </html>
Q4. Explain looping in java script.
Looping in programming languages is a feature that facilitates
the execution of a set of instructions/functions repeatedly while
some condition evaluates to true. For example, suppose we want
to print “Hello World” 10 times. This can be done in two ways as
shown below:
Iterative Method: The iterative method to do this is to write the
document.write() statement 10 times.

Many things may seem confusing to you in the above program at


this point of time but do not worry you will be able to understand
everything about loops in JavaScript by the end of this tutorial.
You can observe that in the above program using loops we have
used the document.write statement only once but still, the output
of the program will be the same as that of the iterative program
where we have used the document.write statement 10 times. In
computer programming, a loop is a sequence of instructions that
is repeated until a certain condition is reached.
• An operation is done, such as getting an item of data and
changing it, and then some condition is checked such as
whether a counter has reached a prescribed number.
There are mainly two types of loops:
1. Entry Controlled loops: In these types of loops, the test
condition is tested before entering the loop body. For
Loops and While Loops are entry-controlled loops.
2. Exit Controlled loops: In these types of loops the test
condition is tested or evaluated at the end of the loop body.
Therefore, the loop body will execute at least once,
irrespective of whether the test condition is true or false.
The do-while loop is exit controlled loop.
Q 24. 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.
<html> <head>
<title>HTML Form</title>
<script language="javascript" type="text/javascript">
function getPage(choice)
{
page=choice.options[choice.selectedIndex].value;
if(page != "")
{
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>
Q Differentiate between concat() and join() methods of array
object.
concat() join()
1) Array elements can be 1) Array elements can be
combined by using concat() combined by using join()
method of Array object. method of Array object.
2) The concat() method 2) The join() method also uses
separates each value with a a comma to separate values,
comma. but you can specify a character
other than a comma to separate
values.
3) Eg: 3) Eg:
var str = cars.concat() var str = cars.join(' ')
The value of str is The value of str in this case is
'BMW, Audi, Maruti' 'BMW Audi Maruti'
Q Different between Client side scripting and Server side
scripting.
Client-side scripting Server-side scripting
1) Source code is visible to 1) Source code is not visible to the
the user. user because its output
of server-sideside is an HTML
page.

2) Its main function is to 2) Its primary function is to


provide the requested manipulate and provide access to
output to the end user. the respective database as per the
request.
3) It usually depends on 3) In this any server-side
the browser and its version. technology can be used and it does
not depend on the client.
4) It runs on the user’s 4) It runs on the webserver.
computer.
5) There are many 5) The primary advantage is its
advantages linked with this ability to highly customize,
like faster. response times, response requirements, access
a more interactive rights based on user.
application.
6) It does not provide 6) It provides more security for
security for data. data.
HTML, CSS, and PHP, Python, Java, Ruby are used.
javascript are used.
Q. Differentiate between prompt() and alert() methods
prompt() alert()
1) A prompt box is used when we 1) An alert box is used
want the user to input a value before if we want the
entering a page. information comes
through to the user.
2) Its syntax is -: 2) Its syntax is -:
window.prompt(“sometext”,”defaultT window.alert(“sometex
ext”); t”);
3) We need to click “OK” or “Cancel” 3) It always return true
to proceed after entering an input we always need to
value when a prompt box pops up on a click on “OK” to
webpage. proceed further.
4) If we click “OK” the box returns 4) The alert box takes
the input value. the focus away from
the current window and
forces the browser to
read the message.
5) If we click “Cancel” the box returns 5) We need to click
a null value. “OK” to proceed when
an alert box pops up.
Q. Differentiate between bession cookies and persistent
cookies

Cookie Session

1) Cookies are client-side


files on a local computer 1) Sessions are server-side files that
that hold user contain user data.
information.

2) When the user quits the browser


2) Cookies end on the
or logs out of the programmed, the
lifetime set by the user.
session is over.

3) It can only store a 3) It can hold an indefinite quantity


certain amount of info. of data.

4) We can keep as much data as we


4) The browser’s cookies like within a session, however there
have a maximum capacity is a maximum memory restriction of
of 4 KB. 128 MB that a script may consume
at one time.

5) Because cookies are


kept on the local
5) To begin the session, we must use
computer, we don’t need
the session start() method.
to run a function to start
them.

6)Cookies are not 6) Session are more secured


secured. compare than cookies.

You might also like