QBCSS Solve
QBCSS Solve
<!DOCTYPE html>
<html>
<head>
<title>Multiple of 3 or 7</title>
</head>
<body>
<script>
function checkMultiple(num) {
if (num % 3 === 0 && num % 7 === 0) {
return num + " is a multiple of both 3 and 7.";
} else if (num % 3 === 0) {
return num + " is a multiple of 3.";
} else if (num % 7 === 0) {
return num + " is a multiple of 7.";
} else {
return num + " is not a multiple of 3 or 7.";
}
}
key n:value n
};
obj_name – Each object should be uniquely identified by a name or IDs in webpage to
distinguish between them.
property – The data in the object is stored in key-value pairs, called a property. The key
is a string while value can be any data-type, including another object.
-Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Object Example</title>
<script>
let bag = {
books: 3,
snacks: ['apple', 'chips'],
bottle: "full",
addBooks: function() {
this.books++;
}
};
In JavaScript, operators are symbols or keywords that perform operations on variables and
values. The different types of operators in JavaScript include:
1. Arithmetic Operators
2. Assignment Operators
3. Comparison Operators
4. Logical Operators
5. Bitwise Operators
6. String Operators
7. Conditional (Ternary) Operator
8. Type Operators
Arithmetic Operators
<head>
<title>Op</title>
<script>
let a = 10;
let b = 5;
</script></head><body></body></html>
6. Explain any four features of JS.
o Lightweight: JavaScript is designed to be easy to use and has a small footprint, making
it efficient for web development.
o Dynamic Typing: Variables in JavaScript do not need to declare a type. A variable can
hold different types of data at different times.
o Interpreted Language: JavaScript code is executed directly by the web browser without
the need for prior compilation.
o Event-Driven: JavaScript responds to events like user actions (clicks, key presses),
making it ideal for interactive web pages.
o Versatile: JavaScript can be used for both front-end (client-side) and back-end (server-
side) development.
o Object-Based: Although not purely object-oriented, JavaScript supports objects and can
create and manipulate them
functionName: The name you give to your function. It should be descriptive of what the
function does.
parameters: Optional. These are input values that the function can receive when called. They
are separated by commas.
Function body: The code inside the curly braces {} is executed when the function is called.
9. WAP to replace “like” by “know” and divide the string on the basis
of white spaces from the 7th index and display results. (Given string
= “I like JavaScript programming”)
<!DOCTYPE html>
<html>
<head>
<title>String Manipulation</title>
</head>
<body>
<script>
// Given string
let givenString = "I like JavaScript programming";
// Display results
document.write('<p>Modified String: ' + modifiedString + '</p>');
document.write('<p>Part 1: ' + part1 + '</p>');
document.write('<p>Part 2: ' + part2 + '</p>');
</script>
</body>
</html>
10. WAP to count and display the number of vowels in a given string.
<!DOCTYPE html>
<html>
<head>
<title>Count Vowels</title>
</head>
<body>
<script>
function countVowels(str) {
// Define vowels
let count = 0;
// Count vowels
if (vowels.includes(char)) {
count++;
return count;
// Given string
// Count vowels
</script>
</body>
</html>
11. Explain what an array is and how to declare an array along with examples.
An array in JavaScript is a special data structure that allows you to store multiple values in a
single variable. These values can be of any type, including numbers, strings, objects, or even
other arrays. Arrays are ordered collections, meaning the values are stored in a specific
sequence, and each value can be accessed by its index, which starts at 0.
Indexed: Each element in an array has a numeric index, starting from 0 for the first element.
Dynamic: Arrays can grow or shrink in size; you can add or remove elements as needed.
Mixed Types: Arrays can store elements of different types (e.g., numbers, strings, objects).
1) JS array literal
Syntax: var array-name = [val1, val2...valn];
Example: var fruits = ["apple", "banana", "cherry"];
console.log(fruits); // Outputs: ["apple", "banana", "cherry"]
2) Creating instance of array directly
Syntax: var array_name =new Array ( ); // declaration
array_name[0] = val1;
array_name[1] = val2; //initialization
Example: var colors = new Array(); // Declare an empty array
colors[0] = "red"; // Initialize elements
colors[1] = "green";
colors[2] = "blue";
console.log(colors); // Outputs: ["red", "green", "blue"]
3) JS array constructor
Syntax: var array_name = new Array (val1, val2..., valn);
Example: var numbers = new Array(10, 20, 30, 40);
console.log(numbers); // Outputs: [10, 20, 30, 40]
12. WAP to find and display the duplicate values along with the count in an integer array.
<!DOCTYPE html>
<html>
<head>
<title>Find Duplicates</title>
</head>
<body>
<script>
function findDuplicates(arr) {
const counts = {};
const duplicates = {};
// Find duplicates
for (const num in counts) {
if (counts[num] > 1) {
duplicates[num] = counts[num];
}
}
return duplicates;
}
// Given array
const givenArray = [1, 2, 3, 2, 4, 5, 1, 6, 1];
// Find duplicates
const duplicateCounts = findDuplicates(givenArray);
// Display result
document.write('<p>Given Array: ' + givenArray + '</p>');
document.write('<p>Duplicates and Counts:</p>');
for (const [num, count] of Object.entries(duplicateCounts)) {
document.write('<p>Number ' + num + ' appears ' + count + ' times</p>');
}
</script>
</body>
</html>
13. What is a Form?
In JavaScript, a form typically refers to an HTML form element that allows users to
submit data to a web server. Forms are a fundamental part of web development, enabling
user interaction and data collection, such as filling out surveys, signing up for
newsletters, or submitting login credentials.
Form Element (<form>): The container that holds all form-related input elements.
Input Elements: Various HTML elements like <input>, <textarea>, <select>, etc., where
users can enter data.
Submit Button: A button that triggers the submission of the form data to the server.
button Type
The button type creates a clickable button in a form. Unlike the submit button, which submits
the form data, a button can be used for any purpose, including triggering JavaScript actions.
Key Attributes:
The checkbox type creates a checkbox, allowing the user to select one or more options. Multiple
checkboxes can be used together to provide multiple selection options.
Key Attributes:
date Type
The date type creates an input field that allows the user to select a date from a date picker. The
selected date is typically in the format YYYY-MM-DD.
Key Attributes:
Example:
The email type creates an input field for email addresses. The browser can validate the input to
ensure it follows the standard email format (e.g., [email protected]).
Key Attributes:
file Type
The file type creates an input field that allows the user to upload files from their device. This is
often used for uploading documents, images, or other files to a server.
Key Attributes:
Example: