Found 6710 Articles for Javascript

JavaScript Program to check idempotent matrix

Prabhdeep Singh
Updated on 20-Apr-2023 17:16:20

177 Views

An idempotent matrix is a square matrix that has the same number of rows and columns and when we multiply the matrix by itself the result will be equal to the same matrix. We will be given a matrix and we have to find that whether it is an idempotent matrix or not. Mathematically − If the given matrix ix M, then of M to be an idempotent matrix is should follow the property − M*M = M Multiplication of Matrix Multiplication of a matrix with another matrix produces another matrix and if the given matrix is the square ... Read More

JavaScript Program to Count Rotations Divisible by 8

Shubham Vora
Updated on 20-Apr-2023 17:02:54

187 Views

Problem Statement − We have given a number. We need to rotate the number and need to find the total number of rotations divisible by 8. Here, we will learn two different approaches to counting rotations divisible by 8. Rotate the Number and Check if Rotation is Divisible by 8 The first approach is to rotate numbers and get every possible rotation one by one. Also, check if rotation is divisible by 8. If yes, add 1 to the count. Syntax Users can follow the syntax below to count rotations divisible by 8 by rotating the numbers. for ( ) ... Read More

JavaScript Program to Count Rotations Divisible by 4

Shubham Vora
Updated on 20-Apr-2023 17:02:19

207 Views

In this tutorial, we will learn to count the total number of rotations divisible by 4 for the given number. Problem statement − We have given a number value. We need to rotate numbers in clockwise or anti-clockwise directions and count the total number of rotations divisible by 4. Here, we will learn two different approaches to counting rotations divisible by 4. Rotate the Number and Check if it is Divisible by 4 In this approach, we will convert the number to a string first. We can make n rotations for the string of length n. We will remove the ... Read More

JavaScript Program to Count Inversions of size three in a given array

Shubham Vora
Updated on 20-Apr-2023 17:00:45

188 Views

In this tutorial, we will learn to count inversions of size three in a given array. Problem statement − We have given an array of length n containing the different numeric entries. We need to find the total number of pairs of numbers of size 3 such that arr[i] > arr[j] > arr[k], where I < j < k. Here, we will learn the brute force approach first and after that, we will optimize its time and space complexity. Using the Brute Force Approach In the brute force approach, we will use three nested for loops to find a count ... Read More

JavaScript Program to Check whether a Given Number is Power of 2

Shubham Vora
Updated on 03-Dec-2024 14:37:26

3K+ Views

To check whether a given number is power of 2 in JavaScript, we can check if the number is generated using multiplying 2's only. We will be discussing 5 different approaches to check whether a given number is a power of 2. In this article we are having two numbers, our task is to check whether a given number is power of 2 in JavaScript. Users must be familiar with JavaScript Math functions, loops, binary representation and bitwise operators. Approaches to Check if a Number is Power of 2 Here is a list of approaches to check whether ... Read More

How to conditionally add a member to an object using JavaScript?

Shubham Vora
Updated on 20-Apr-2023 16:32:29

3K+ Views

The object is the most important data type of JavaScript. Even everything is an object in JavaScript. For example, Array is an object, and Number, String, and Boolean can also be an object. Sometimes, developers require to insert properties into the object based on some condition. For example, we have an object of the person, and we only require adding the driving licence property if a person is 18 years old. Here, we will learn different approaches to adding a member to an object using JavaScript conditionally. Using the Spread Operator to add a Member to an Object Conditionally The ... Read More

How to Get Value of Selected Radio Button Using JavaScript?

Yaswanth Varma
Updated on 22-Nov-2024 11:06:00

9K+ Views

To get value of selected radio button using JavaScript is useful to a user in various ways such as collecting surveys data, in quiz or dynamic UI updates like changing to dark or light theme. We will be discussing two approaches to get the selected radio button value. In this article, we are having three radio buttons with their labels and our task is to get value of selected radio button using JavaScript. Approaches to Get Value of Selected Radio Button Here is a list of approaches to get value of selected radio button using JavaScript which we will be ... Read More

How To Password Protect A Page Using Only HTML, CSS And JavaScript?

Yaswanth Varma
Updated on 24-Oct-2024 17:29:01

25K+ Views

To password protect a page using only HTML, CSS and JavaScript, is an important security measure for webpages that contain sensitive information or require authentication for access. In this article, we will understand how to create a simple form that requires users to enter a password before they can view the content of your protected page. In this article, we are having some textual information, our task is to password protect page using only HTML, CSS and JavaScript. Approaches to Password Protect a Page Here is a list of approaches to password protect a page using only HTML, CSS and ... Read More

How to Show Today's Year And Random 4Digit Numbers at the Same Time?

Yaswanth Varma
Updated on 20-Apr-2023 16:44:17

162 Views

Let's see "How to show the current year and a random 4-digit number at the same time." This can be useful for a variety of reasons, such as creating unique identifiers, tracking dates, or displaying the date in a specific format. By using some simple programming techniques, you can quickly create this effect with minimal coding knowledge. Let's explore how to do it in JavaScript. Let’s dive into the article to get a better understanding of displaying today's year and a random 4-digit number at the same time. Using JavaScript random() method The Math.random() static method provides a floating-point, pseudo-random ... Read More

How To Change Text Inside All HTML Tags Using JavaScript

Yaswanth Varma
Updated on 20-Apr-2023 16:15:35

1K+ Views

In this article, we are going to perform the task of changing text inside all HTML tags using JavaScript. Let's dive into the article to learn more about changing text within all HTML, but first, let's define HTML tags. What are HTML tags An HTML tag is a segment of markup language used to denote the start and end of an HTML element in an HTML document. HTML tags, which are a component of an HTML element, assist web browsers in turning HTML documents into web pages. For getting better understanding on changing text inside all HTML tags using JavaScript. ... Read More

Advertisements