AmitDiwan

AmitDiwan

8,392 Articles Published

Articles by AmitDiwan

Page 448 of 840

Checking semiprime numbers - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 448 Views

We are required to write a JavaScript function that takes in a number and determines if the provided number is a semiprime or not. What is a Semiprime? A semiprime number is a special type of composite number that is the product of exactly two prime numbers (not necessarily distinct). For example: 6 = 2 × 3 (product of two distinct primes) 15 = 3 × 5 (product of two distinct primes) 10 = 2 × 5 (product of two distinct primes) 4 = 2 × 2 (square of a prime) 9 = 3 × 3 ...

Read More

How to create animations using JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 364 Views

JavaScript animations are created by repeatedly changing CSS properties over time using functions like setInterval() or requestAnimationFrame(). This allows you to create smooth visual effects directly in the browser. Basic Animation Principles JavaScript animations work by: Selecting the element to animate Using a timer function to repeatedly update CSS properties Incrementing position, size, or other properties each frame Stopping the animation when the target is reached Example: Moving and Morphing Animation ...

Read More

Get value from div with JavaScript resulting undefined?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 3K+ Views

When trying to get the value from a div element using JavaScript, you might encounter undefined results if you use incorrect properties. The key is understanding the difference between innerHTML, textContent, and value. The Problem The most common mistake is using .value on div elements. The value property only works for form inputs like , , and . For div elements, use innerHTML or textContent. Using innerHTML innerHTML gets the HTML content inside the element, including any HTML tags: Get Div Value ...

Read More

Single dimensional array vs multidimensional array in JavaScript.

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 825 Views

JavaScript supports both single-dimensional and multidimensional arrays. A single-dimensional array stores elements in a linear sequence, while a multidimensional array contains arrays as elements, creating a matrix-like structure. Single-Dimensional Arrays A single-dimensional array is a simple list of elements accessed by a single index. Single Dimensional Array let singleArray = [10, 20, 30, 40, 50]; console.log("Single-dimensional array:", ...

Read More

How to selectively retrieve value from json output JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 268 Views

We have the following data inside a JSON file data.json: data.json { "names": [{ "name": "Ramesh", "readable": true }, { "name": "Suresh", "readable": false }, { "name": "Mahesh", "readable": true }, { "name": "Gourav", "readable": true }, { "name": "Mike", "readable": false }] } ...

Read More

Can JavaScript parent and child classes have a method with the same name?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

Yes, JavaScript parent and child classes can have methods with the same name. This concept is called method overriding, where the child class provides its own implementation of a method that already exists in the parent class. Method Overriding Example class Parent { constructor(parentValue) { this.parentValue = parentValue; } // Parent class method showValues() { console.log("The parent method is called....."); ...

Read More

Mapping unique characters of string to an array - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 486 Views

We are required to write a JavaScript function that takes in a string and starts mapping its characters from 0. Every time the function encounters a unique (non-duplicate) character, it should increase the mapping count by 1, otherwise map the same number for duplicate characters. For example, if the string is: const str = 'heeeyyyy'; Then the output should be: const output = [0, 1, 1, 1, 2, 2, 2, 2]; How It Works The algorithm works by tracking consecutive character groups. When a character differs from the previous one, ...

Read More

Finding reversed index of elements in arrays - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

We need to create a JavaScript function that finds the reversed index of an element in an array without actually reversing it. This function calculates what position an element would occupy if the array were reversed. If the element is not present in the array, the function returns -1. Otherwise, it returns the index position the element would have in a reversed array. Understanding Reversed Index The reversed index is calculated using the formula: length - originalIndex - 1 For example, in array [45, 74, 34, 32, 23, 65]: Element 23 is at index 4 ...

Read More

How to override derived properties in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 398 Views

In JavaScript, when an object inherits properties from its prototype, you can override those inherited properties by assigning new values directly to the child object. This creates own properties that shadow the prototype properties. Understanding Property Inheritance When you create an object using Object.create(), the new object inherits properties from its prototype. These inherited properties can be overridden by setting properties directly on the derived object. Example: Overriding Derived Properties Override Derived Properties ...

Read More

How to draw a circle in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

Drawing circles in JavaScript is accomplished using the HTML5 Canvas API and the arc() method. This method allows you to create perfect circles and arcs with precise control over position, size, and styling. Basic Circle Drawing Syntax context.arc(x, y, radius, startAngle, endAngle, counterclockwise); Parameters Parameter Description x, y Center coordinates of the circle radius Circle radius in pixels startAngle Starting angle (0 for full circle) endAngle Ending angle (2 * Math.PI for full circle) Interactive Circle Example ...

Read More
Showing 4471–4480 of 8,392 articles
« Prev 1 446 447 448 449 450 840 Next »
Advertisements