Articles on Trending Technologies

Technical articles with clear explanations and examples

What are the ways to include style sheet rules in an HTML document

seetha
seetha
Updated on 15-Mar-2026 769 Views

There are three main ways to include CSS styles in an HTML document: inline styles using the style attribute, internal stylesheets using the element, and external stylesheets using the element. Method 1: Inline Styles Inline styles are applied directly to HTML elements using the style attribute: Inline Styles Example Inline Styled Heading This paragraph has inline styles. Method 2: Internal Stylesheets Internal stylesheets are defined within the element in the document's ...

Read More

Calculating average of an array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 726 Views

Calculating the average of an array is a common task in JavaScript. The average is computed by summing all elements and dividing by the array length. Basic Formula Average = (Sum of all elements) / (Number of elements) Method 1: Using forEach Loop Calculate Array Average Calculating Average of an Array Array: Calculate Average ...

Read More

Get minimum number without a Math function JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 369 Views

We need to find the smallest number from a set of numbers without using JavaScript's built-in Math.min() function. This requires implementing our own comparison logic. Approach Using While Loop We'll iterate through all numbers and keep track of the smallest value found so far, updating it whenever we encounter a smaller number. Example const numbers = [12, 5, 7, 43, -32, -323, 5, 6, 7, 767, 23, 7]; const findMin = (...numbers) => { let min = Infinity, len = 0; while(len < numbers.length) { ...

Read More

Creating a JavaScript Object from Single Array and Defining the Key Value?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 232 Views

JavaScript provides several ways to create objects from arrays and define key-value pairs. This is useful when transforming data structures or converting between different formats. Using Object.entries() with map() The most common approach uses Object.entries() to convert an object into an array of key-value pairs, then map() to transform the structure: var studentObject = { 101: "John", 102: "David", 103: "Bob" }; var studentDetails = Object.entries(studentObject).map(([studentId, studentName]) => ({ studentId, studentName })); console.log(studentDetails); ...

Read More

Take two numbers m and n & return two numbers whose sum is n and product m in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 308 Views

We need to write a JavaScript function that takes two numbers m (product) and n (sum) and returns two numbers whose sum equals n and product equals m. If no such numbers exist, the function should return false. This is essentially solving a quadratic equation where we need to find two numbers x and y such that x + y = n and x × y = m. Mathematical Approach We can solve this using the quadratic formula. If x + y = n and x × y = m, then x and y are roots of ...

Read More

How to search and display the pathname part of the href attribute of an area with JavaScript?

Vrundesha Joshi
Vrundesha Joshi
Updated on 15-Mar-2026 239 Views

To get the pathname part of the href attribute of an area in JavaScript, use the pathname property. This property extracts just the path portion from a URL, excluding the protocol, domain, and query parameters. Syntax areaElement.pathname Example You can try to run the following code to display the pathname part of an area element's href attribute. ...

Read More

How to change date time format in HTML5?

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 3K+ Views

HTML5 provides several input types for date and time, but formatting them requires JavaScript. The default browser format can be customized using JavaScript date methods or libraries. HTML5 Date Input Types HTML5 offers various date and time input types: Basic Date Formatting with JavaScript You can format dates using JavaScript's built-in methods: const dateInput = document.getElementById('dateInput'); const output = document.getElementById('output'); dateInput.addEventListener('change', function() { const date = new Date(this.value); ...

Read More

Working with element for CSS

Samual Sam
Samual Sam
Updated on 15-Mar-2026 131 Views

You can put your CSS rules into an HTML document using the element. This tag is placed inside ... tags. Rules defined using this syntax will be applied to all the elements available in the document. Syntax /* CSS rules go here */ selector { property: value; } Example Following is an example of embedded CSS ...

Read More

Calculating median of an array in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 4K+ Views

In this problem statement, our task is to calculate the median of an array with the help of Javascript functionalities. There are several ways that can be used to solve this task. One simple method to calculate median is using the built-in function of Javascript. Understanding the Problem The problem statement is to write a function in Javascript that will help to calculate the median of a given array. The median is the middle value when numbers are arranged in ascending order. For example: Array [1, 2, 3, 4, 5] has median 3 (middle element) Array ...

Read More

From an array of arrays, return an array where each item is the sum of all the items in the corresponding subarray in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 411 Views

Given an array of arrays, each of which contains a set of numbers. We have to write a function that returns an array where each item is the sum of all the items in the corresponding subarray. For example, if we have nested arrays with numbers, we want to calculate the sum of each inner array and return those sums as a new array. Example Input and Expected Output If the input array is: const numbers = [ [1, 2, 3, 4], [5, 6, 7], [8, ...

Read More
Showing 18531–18540 of 61,299 articles
Advertisements