An overview of the key concepts and features in css and javascript, which are essential for web development. It covers topics such as css properties, selectors, and pseudo-classes, as well as javascript variables, operators, decision control statements, and event handling. The document also includes discussions on specific css and javascript features, such as font properties, string methods, and operators. This comprehensive coverage of css and javascript fundamentals makes this document a valuable resource for students and web developers looking to strengthen their understanding of these core web technologies.
Download CSS and JavaScript Fundamentals for Web Development and more Exams Web Programming and Technologies in PDF only on Docsity!
PHP Module 2 (Previous Year QP Discussion)
Sem 4 BCA/B.Sc. Computer Science MGU
Module 2 Overview
CSS introduction, and
2. What are pseudo classes in CSS [2019] [2 Marks]
Special keywords used to select & style elements based on their current state or position in the document tree.
allows you to apply styles to elements that cannot be selected using regular class or ID selectors.
Denoted by a colon ā:ā followed by the name of the pseudo-class.
Example for pseudo-classes in CSS:
:hover : Applies style to element when user hovers over it with the mouse pointer.
:disable: Applies style to disabled input element
3. List any four number object methods in JavaScript [2019] [2 Marks]
1. toFixed() : Converts a number into a string, keeping a specified number of decimals.
Eg:
const num = 10.456;
const formattedNum = num.toFixed( 2 ); // Returns "10.46" as a string
2. toPrecision() : Converts a number into a string, using the specified precision. It represents the total number of
significant digits (including both integer and decimal digits).
Eg:
const num = 123.456789;
const formattedNum = num.toPrecision(5); // Returns "123.46" as a string
3. toString() : Converts a number to a string. You can also specify the base for the string representation (2 for binary, 8 for
octal, 16 for hexadecimal)
Eg:
const num = 42;
const numAsStr = num.toString(); // Returns "42" as a string
const numAsBinary = num.toString(2); // Returns "101010" as a binary string
4. Explain any five number array methods in JavaScript [2019] [5 Marks]
push() - adds one or more elements to the end of an array and returns the updated length of the array. const numbers = [ 1 , 2 , 3 ]; numbers.push( 4 , 5 ); // Adds 4 and 5 to the end of the array console.log(numbers); // Output: [1, 2, 3, 4, 5]
pop() : removes the last element from an array and returns that element. const numbers = [ 1 , 2 , 3 , 4 , 5 ]; const lastNumber = numbers.pop(); // Removes 5 from the array console.log(numbers); // Output: [1, 2, 3, 4] console.log(lastNumber); // Output: 5
indexOf() : returns the index of the first occurrence of a specified element in an array. If the element is not found, it returns - 1. const fruits = ["apple", "banana", "orange", "banana"]; const index = fruits.indexOf("banana"); // Returns 1 (index of the first "banana")
forEach() : executes a provided function once for each element in the array. const numbers = [ 1 , 2 , 3 , 4 , 5 ]; numbers.forEach((number) => { console.log(number * 2 ); // Outputs the double of each number });
map() : creates a new array by applying a provided function to each element of the original array. It returns a new array with the results of calling the provided function on each element of the original array. const numbers = [ 1 , 2 , 3 , 4 , 5 ]; const doubledNumbers = numbers.map((number) => number * 2 ); console.log(doubledNumbers); // Output: [2, 4, 6, 8, 10]
Explain difference between Prompt Box & Confirm Box [2019] [5 Marks] For Notes download BCA Resources App
Both prompt boxes and confirm boxes are used to interact with users in JavaScript, but they serve different purposes.
Prompt Box
used to get input from the user.
displays a dialog box with a message, an input field, and "OK" and "Cancel" buttons.
user can type a response in the input field and choose to click "OK" or "Cancel.ā
prompt() function is used for creating a prompt
Example code: const userInput = prompt("Please enter your name:"); if (userInput !== null) { console.log("Hello, " + userInput); } else { console.log("You cancelled the prompt."); }
Confirm Box
used to get a binary choice from the user, typically for confirmation purposes.
displays a dialog box with a message and "OK" and "Cancel" buttons.
The user can choose to click "OK" or "Cancel.ā
confirm() function is used for creating a confirm box.
Example Code: const result = confirm("Are you sure you want to delete this item?"); if (result) { console.log("Item deleted."); } else { console.log("Deletion cancelled."); }
Explain different types of Selectors in CSS. Give Examples [2019] [15 Marks]
Child Selector: Targets an element that is a direct child of another element. It selects elements that are immediate children of a parent. Example: HTML: Item 1 Item 2 CSS: ul > li { list-style: none; }
Attribute Selector: Targets elements based on their attribute values. Example: HTML: Visit Example CSS: a[href^="https://"] { color: blue; }
Pseudo-class Selector: Targets elements based on their state or position in the document tree. Example: HTML: Link CSS : a:hover { text-decoration: underline; }
When is an internal CSS is used in HTML document? [2 Marks] [2020] Internal CSS is used in an HTML document when you want to apply styles directly to specific elements or groups of elements within that particular HTML file. Internal CSS is defined within the `
Welcome to My Website
Internal CSS is suitable for smaller HTML documents or when you need to apply specific styles unique to a particular HTML file. However, it is not recommended for larger projects or when you want to reuse styles across multiple HTML files, as this can lead to redundant code.
Discuss CSS Font properties in detail [ 5 marks ] [ 2020 ]
1. font-family: sets the font family for an element, specifying the font(s) to be used for displaying
text content. You can specify multiple font families in order of priority, separated by commas. If
the browser doesn't support the first font, it will try the next one in the list.
Example: p { font-family: Arial, sans-serif; }
2. font-size: sets the size of the text. It can be specified in various units like pixels (px), ems (em), or
percentages (%).
Example: p{font-size:24px;}
3. font-weight: defines the thickness or boldness of the font. It can have values like normal, bold,
bolder, lighter, or numeric values (e.g., 400, 700)
Example: p{font-weight: bold;}
4. font-style: used to specify the style of the font. It can be set to normal, italic, or oblique.
Example: p{font-style: italic;}
5. text-decoration : used to add decorative elements to text, such as underlines, overlines, line-
through, or blinking text.
Example: a { text-decoration: underline; }
Create a String object in JavaScript & apply any four built-in String object Methods [ 5 marks ] [ 2020 ] In JavaScript, you can create a String object by using the String constructor or by simply using a string literal (a sequence of characters enclosed in single or double quotes). When a string is created using a string literal, JavaScript automatically converts it to a String object behind the scenes, so you can use built-in String methods on it. const myString = new String("Hello, World!"); console.log(myString.length); // Output: 13 (length of the string) console.log(myString.toUpperCase()); // Output: HELLO, WORLD! (converts to uppercase) console.log(myString.indexOf("World")); // Output: 7 (index of the substring "World") console.log(myString.replace("World", "Universe")); // Output: Hello, Universe! (replaces "World" with "Universe") length: This property returns the length of the string, which is the number of characters in the string. toUpperCase(): This method returns a new string with all characters converted to uppercase. indexOf(substring): This method returns the index of the first occurrence of the specified substring in the original string. If the substring is not found, it returns - 1. replace(searchValue, newValue): This method returns a new string where all occurrences of the searchValue are replaced with the newValue.
Explain various operators supported by JavaScript. Give Example [ 15 marks ] [ 2020 ] Comparison Operators: [Asked in 2021 for 5 marks] ==: Equal to, checks if two values are equal (value comparison). !=: Not equal to, checks if two values are not equal. ===: Strict equal to, checks if two values are equal and have the same data type (value and type comparison). !==: Strict not equal to, checks if two values are not equal or have different data types. >: Greater than, checks if the left value is greater than the right value. <: Less than, checks if the left value is less than the right value. >=: Greater than or equal to, checks if the left value is greater than or equal to the right value. <=: Less than or equal to, checks if the left value is less than or equal to the right value.
let x = 5;
let y = 10;
let isEqual = x == y; // false
let isNotEqual = x != y; // true
let isStrictEqual = x === "5"; // false (different data types)
let isGreaterThan = y > x; // true
Explain various operators supported by JavaScript. Give Example [ 15 marks ] [ 2020 ] Logical Operators: &&: Logical AND, returns true if both operands are true. ||: Logical OR, returns true if at least one operand is true. !: Logical NOT, returns true if the operand is false and vice versa. let isTrue = true; let isFalse = false; let result1 = isTrue && isFalse; // false let result2 = isTrue || isFalse; // true let result3 = !isFalse; // true
Explain various operators supported by JavaScript. Give Example [ 15 marks ] [ 2020 ] Conditional (Ternary) Operator: Syntax : condition? expr1 : expr2: The conditional operator is a shorthand way to write an if-else statement. It evaluates the condition, and if it is true, it returns expr1; otherwise, it returns expr2. let age = 18; let message = age >= 18? "You are an adult" : "You are a minor";
What is an event. Give Example [ 2 marks ] [ 2021 ] An event is an action or occurrence that happens within the browser window or a web page. Events can be triggered by user interactions, changes in the web page's state, or specific actions performed by the browser. JavaScript allows you to respond to these events by attaching event handlers to elements on the web page. An event handler is a function that gets executed when a specific event occurs. Example: (HTML) Click Me (JS) // Get a reference to the button and paragraph elements const button = document.getElementById('myButton'); const output = document.getElementById('output'); // Define an event handler function function handleClick() { output.textContent = "Button clicked!"; } // Attach the event handler to the button element button.addEventListener('click', handleClick);