Final CSS
Final CSS
Syntax:
1. JavaScript is a object-based scripting language. function func_name(parameter1 ,parameter2,…,parametern)
2. Giving the user more control over the browser. {
3. It Handling dates and time. //code
4. It Detecting the user's browser and OS, }
5. It is light weighted. Example:
6. Client – Side Technology <script>
7. JavaScript is a scripting language and it is not java. function add(num1,num2)
8. JavaScript is interpreter based scripting language. { return num1 + num2; }
9. JavaScript is case sensitive. add(1,2);
</script>
Q. explain the term in javascript URL
In JavaScript, a URL (Uniform Resource Locator) is a string
that specifies the location of a resource on the internet. It Q. State any two properties and methods of location object.
typically consists of several parts: the protocol (such as "http" 1. hash 2. Host 3. Hostname 4. Href 5. origin
or "https"), the domain name (like "example.com"), and 6. pathname 7. Port 8. Protocol 9. search
optional components like the path, query parameters, and Methods of location object:
fragment identifier. JavaScript provides built-in methods and 1. assign( ) 2. reload( ) 3. replace( )
properties to manipulate and work with URLs, allowing
developers to extract information like the hostname, Q. Give syntax of and explain the use of small “with” clause.
pathname, or search parameters. “with” clause is used to directly access the properties and
method of an object.
Q.3List and explain any six form events Syntax:
1. Onmousedown- Fires when a mouse button is with (object)
pressed down on an element {
2. Onmousemove- Fires when the mouse pointer is //object
moving while it is over an element }
3. onmouseout -Fires when the mouse pointer moves Example:
out of an element <script>
4. onmouseover- Fires when the mouse pointer moves var person ={ name:"Abc", age:18
over an element }
5. onmouseup -Fires when a mouse button is released with(person){ docment.write(name); docment.write(age);
over an element }
</script>
Q.4 Math Functions
1. *Math.abs()*: Q. With the help of suitable example explain the Date
- *Description*: Returns the absolute value of a number, object and any two methods of
which is the number's distance from zero without Date object.
considering its sign. “Date” object is used when we want to perform some
- *Example*: Math.abs(-5) returns 5. operation on date, it has various
2. *Math.random()*: method which helps you performs some task related to date,
- *Description*: Generates a pseudo-random floating-point Example:
number between 0 (inclusive) and 1 (exclusive). <script>
- *Example*: Math.random() might return 0.357896. var date = new Date();
3. *Math.floor()*: document.write(date.getDate()); // get the current date
- *Description*: Rounds a number downward to the document.write(date.getFullYear()); // get the current Year
nearest integer. document.write(date.getMinutes()); // get the current
- *Example*: Math.floor(4.7) returns 4. minutes
4. *Math.pow()*: - *Description*: Raises a base number to </script>
the power of an exponent (base^exponent).
- *Example*: Math.pow(2, 3) returns 8. Q. Differentiate between shift() and push() methods of an
Array object.
Q. 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.
Q. Explain getter and setter properties in Java script with Q. Write the use of chatAt() and indexof() with syntax and
suitable example. example
Property getters and setters charAt()
1. The accessor properties. They are essentially functions The charAt() method requires one argument i.e is the index
that work on of the character that
getting and setting a value. you want to copy.
2. Accessor properties are represented by “getter” and Syntax:var SingleCharacter =
“setter” methods. In NameOfStringObject.charAt(index);
an object literal they are denoted by get and set. Example:
let obj = { var FirstName = 'Bob'
get propName() { var Character = FirstName.charAt(0); //o/p B
// getter, the code executed on getting obj.propName indexOf()
}, The indexOf() method returns the index of the character
set propName(value) { passed to it as an
// setter, the code executed on setting obj.propName = value argument.
} If the character is not in the string, this method returns –
}; 1.Syntax:var indexValue = string.indexOf('character');
3. An object property is a name, a value and a set of Example:
attributes. The value var FirstName = 'Bob';
may be replaced by one or two methods, known as setter var IndexValue = FirstName.indexOf('o'); //o/p index as 1
and a getter.
This Q. Differentiate between concat() and join() methods of
method is responsible for setting the property value. array object.
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"> Q. Enlist & explain the use of any two Intrinsic JavaScript
var myCar = {/* Data properties */ Functions.
defColor: "blue",defMake: "Toyota", An intrinsic function (or built-in function) is a function
/* Accessor properties (getters) */ (subroutine) available for use in a
get color() { given programming language whose implementation is
return this.defColor; handled specially by the compiler.
},get make() { You can use intrinsic functions to make reference to a data
return this.defMake; item whose value is derived
},/* Accessor properties (setters) */ automatically during execution.
set color(newColor) { abs() - The ABS function returns the absolute value of the
this.defColor = newColor; argument.
},set make(newMake) { sin() - The SIN function returns a numeric value that
this.defMake = newMake; approximates the sine of the angle or
}};document.write("Car color:" + myCar.color + " Car Make: arc specified by the argument in radians.
"+myCar.make) sqrt() - The SQRT function returns a numeric value that
/* Calling the setter accessor properties */ approximates the square root of
myCar.color = "red"; the argument specified.
myCar.make = "Audi"; Date(): return current date.
/* Checking the new values with the getter accessor Len(): returns number of characters in the text.parseInt() -
properties */ parseInt() function takes string as a parameter and converts it
document.write("<p>Car color:" + myCar.color); // red to integer.
document.write(" Car Make: "+myCar.make); //Audi parseFloat() - parseFloat() function takes a string as
</script> parameter and parses it to a floating
</head> point number.
</body>
</html>
Q. Adding and sorting elements in an array can be Q. An associative array, also known as a dictionary, map, or
illustrated with a simple example. Let's break it down step- hash table, is a data structure that stores data in key-value
by-step: pairs. This allows you to look up values by their
### Adding an Element to an Array corresponding keys efficiently. Associative arrays are
In many programming languages, arrays have a fixed size, so particularly useful when you need a way to quickly retrieve
adding an element might involve creating a new array that data based on a unique identifier.
can accommodate the additional element. In languages like
Python, arrays (lists) can dynamically resize. Here’s an ### Characteristics of Associative Arrays
example in Python: 1. *Key-Value Pair Storage*: Data is stored as pairs of keys
python and values. Each key is unique.
# Original array 2. *Fast Lookup*: Accessing a value by its key is typically very
array = [3, 1, 4, 1, 5] fast.
# Element to add 3. *Dynamic Size*: Associative arrays can grow as needed,
element = 9 and you can add or remove key-value pairs dynamically.
# Add the element to the array ### Example in Python (Dictionary)
array.append(element) Python’s built-in dictionary is a perfect example of an
# Print the updated array associative array.
print(array) python
Output: # Creating an associative array (dictionary)
[3, 1, 4, 1, 5, 9] phone_book = {
### Sorting an Array "Alice": "555-1234",
Once you've added the element, you might want to sort the "Bob": "555-5678",
array. Here's how you can sort the array: "Charlie": "555-8765"
python }# Accessing a value by its key
# Sort the array in ascending order print(phone_book["Alice"]) # Output: 555-1234
array.sort() # Adding a new key-value pair
# Print the sorted array phone_book["David"] = "555-4321"
print(array) # Updating a value
Output: phone_book["Alice"] = "555-0000"
[1, 1, 3, 4, 5, 9] # Reoving a key-value pair
### Complete Example del phone_book["Charlie"]
Combining both steps, here's a complete example in Python: # Iterating over key-value pairs
python for name, number in phone_book.items():
# Initial array print(f"{name}: {number}")
array = [3, 1, 4, 1, 5] ### Example in Java (HashMap)
# Adding a new element In Java, the HashMap class from the java.util package
element_to_add = 9 provides similar functionality.
array.append(element_to_add) java
# Sorting the array import java.util.HashMap;
array.sort() public class Main {
# Display the final sorted array public static void main(String[] args) {
print(array) HashMap<String, String> phoneBook = new
Output: HashMap<>();
[1, 1, 3, 4, 5, 9] phoneBook.put("Alice", "555-1234");
### Example in Java phoneBook.put("Bob", "555-5678");
Here's a similar example in Java: phoneBook.put("Charlie", "555-8765");
java System.out.println(phoneBook.get("Alice
import java.util.Arrays; phoneBook.put("David", "555-4321");
public class Main { phoneBook.put("Alice", "555-0000");
public static void main(String[] args) { phoneBook.remove("Charlie");
int[] array = {3, 1, 4, 1, 5}; for (String name : phoneBook.keySet()) {
int elementToAdd = 9; System.out.println(name + ": " +
int[] newArray = new int[array.length + 1]; phoneBook.get(name));
System.arraycopy(array, 0, newArray, 0, array.length); } }}
newArray[newArray.length - 1] = elementToAdd; ### Key Operations in Associative Arrays
Arrays.sort(newArray); 1. *Insertion*: Adding a new key-value pair.
System.out.println(Arrays.toString(newArray)); 2. *Deletion*: Removing a key-value pair.
} 3. *Update*: Changing the value associated with an existing
} key.
4. *Lookup*: Retrieving the value associated with a key.
5. *Iteration*: Looping through all key-value pairs.
Q. State what is frame ? Explain now it can be created with Q. Develop a JavaScript program to create Rotating Banner
suitable example Ads.
In CSS, a "frame" typically refers to the outer boundary or <html >
container of an element, often used in the context of layout <head>
or design. Frames can be created using various CSS <title>Banner Ads</title>
properties and techniques to define the structure and <script>
appearance of elements on a webpage. Banners = new Array('1.jpg','2.jpg','3.jpg');
### Example: Creating a Frame with CSS CurrentBanner = 0;
<head> function DisplayBanners()
<meta charset="UTF-8"> {if (document.images);
<meta name="viewport" content="width=device-width, {CurrentBanner++;
initial-scale=1.0"> if (CurrentBanner == Banners.length)
<title>Frame Example</title> {CurrentBanner = 0;
</head> }document.RotateBanner.src= Banners[CurrentBanner];
<body> setTimeout("DisplayBanners()",1000);
<div class="frame"> }}</script>
<p class="content">This is a frame created with CSS.</p> </head><body onload="DisplayBanners()" >
</div> <center><img src="1.jpg" width="400"
</body> height="75" name="RotateBanner" />
</html> </center></body></html>