Found 8894 Articles for Front End Technology

How to create infix to postfix converter in JavaScript?

Naveen Singh
Updated on 03-Aug-2022 13:43:50

977 Views

An infix to Postfix converter is a tool that converts an infix expression to a postfix expression. In this tutorial, we will build the infix to postfix converter using JavaScript. What is an infix expression? Infix expression is an expression in which the operators are between the operands. For example, the expression "3 + 4" is an infix expression. What is a postfix expression? A postfix expression is an expression in which the operators are after the operands. For example, the expression "3 4 +" is a postfix expression. How does the Infix to Postfix converter work? The converter first ... Read More

How to implement enqueue and dequeue using only two stacks in JavaScript?

Naveen Singh
Updated on 03-Aug-2022 13:37:11

1K+ Views

In this tutorial, we'll be implementing a queue using only two stacks. This is a pretty common interview question so it's good to know how to do it. Algorithm STEP 1 − We have two stacks, one for enqueueing and one for dequeueing. STEP 2 − We enqueue by pushing onto the enqueue stack. STEP 3 − We dequeue by popping from the dequeue stack. STEP 4 − If the dequeue stack is empty, we pop everything from the enqueue stack and push it onto the dequeue stack. STEP 5 − This reverses the order so that ... Read More

How to negate a predicate function in JavaScript?

Naveen Singh
Updated on 04-Aug-2022 08:13:29

1K+ Views

In JavaScript, a predicate function is a function that returns a Boolean value. In other words, it is a function that tests whether a certain condition is true or false.There are times when we need to negate a predicate function. That is, we need to return the opposite Boolean value.There are several ways to negate a predicate function in JavaScript.Using the ! operatorThe most common way to negate a predicate function is to use the ! operator.For example, consider the following predicate function −function isEven(num) {    return num % 2 === 0; }To negate this function, we can use ... Read More

How to replace characters except last with a mask character in JavaScript?

Naveen Singh
Updated on 03-Aug-2022 13:29:19

2K+ Views

JavaScript has a built-in function called replace() that can be used to replace characters in a string. This function takes two arguments: the first argument is the character or characters to be replaced, and the second argument is the character or characters to replace them with. Syntax Following is the syntax to replace characters except last with a specified mask − str.replace(/.(?=.)/g, "x"); The first argument to the replace() method is character/s to be replaced. We pass a regular expression for all characters except last as the first argument to the replace method. All characters except the last are ... Read More

How to Create Fullscreen API using JavaScript?

Naveen Singh
Updated on 04-Aug-2022 07:58:29

721 Views

The Fullscreen API is a browser API that allows developers to request fullscreen display from the user, and to exit fullscreen when desired. Using the Fullscreen API is relatively simple. First, you must check if the browser you are using supports the Fullscreen API. You can do this by checking for the presence of the Fullscreen API's enabled property on the document object. If the browser does not support the Fullscreen API, you can still provide a fullscreen experience to your users by using another method, such as opening a new browser window. Assuming the browser does support the Fullscreen ... Read More

How to create a chessboard pattern with JavaScript and DOM?

Naveen Singh
Updated on 03-Aug-2022 12:02:51

5K+ Views

With a little bit of JavaScript and DOM manipulation, you can create all sorts of interesting patterns on a webpage. In this tutorial, we'll show you how to create a chessboard pattern using JavaScript and the DOM.ApproachSTEP 1 − We start by creating a element with an id of "chessboard". This will be the element that contains our chessboard pattern.STEP 2 − We create a element that sets the width and height of the #chessboard div to 400px. We also create a class called .chess-square that sets the width and height of elements to 50px and floated to ... Read More

How to change string to be displayed as a superscript using JavaScript?

Naveen Singh
Updated on 02-Aug-2022 11:40:17

2K+ Views

In this tutorial, we are going to learn to change strings to be displayed as a superscript using JavaScript. As the name suggests, the superscript string is displayed at the half-height of the normal string. Also, characters of the superscript string are smaller than the normal string characters.There are a lot of uses of the superscript string while writing the mathematical formulas. For example, A2, B2, 105, etc. Also, we can use the superscript to show the chemical formulas such as O22-, H-, etc.Here, using HTML or JavaScript, users can learn to display string as a superscript.Display string as subscript ... Read More

How to convert 3-digit color code to 6-digit color code using JavaScript?

Kalyan Mishra
Updated on 29-Jul-2022 10:38:47

879 Views

In this tutorial, we will see how to convert 3-digit color code to 6-digit color code in JavaScript.So, basically three-digit color code represents the three-digit value of the colour of the form in #RGB format. To convert 3-digit color hex color to 6-digit we just have to do is convert every element of the three digit and make it duplicate.If we say in easy manner, then duplicating the three-digit color will give the hexadecimal whose value is same as three-digit color value.3-digit value: #RGB will be written as #RRGGBB in 6-digit color code.For example, 3-digit value: #08c 6-digit color Code: ... Read More

How to Create an Analog Clock using HTML, CSS, and JavaScript?

Kalyan Mishra
Updated on 26-Jul-2022 14:41:17

3K+ Views

In this tutorial, we will design an Analog Clock by the help of HTML, and CSS and make it work using JavaScript which will show the current time in hour, minute, and second format.ApproachWe will use the Date object and by using some calculations we will show hour, minute, and second.We will get the system time from JavaScript object Date() and this object has functions like getHours(), getSecond() and getMinutes().After getting hour, minute, and second format we will apply to transform rotation for all three needles hour, minute, and second.An analog clock shows time with its three hands moving continuously, ... Read More

How to swap two array elements in JavaScript?

Kalyan Mishra
Updated on 26-Jul-2022 14:33:55

4K+ Views

In this tutorial, we use different approach to swap two array elements in JavaScript. For example, we swap first and second element of the array asInput −["first", "second", "third", "fourth", "fifth"]Output −["second", "first", "third", "fourth", "fifth"]Here we swapped “first” and “second” value of the array.Now we will look at different methods to swap two elements −Using an extra variableUsing Array Splice() MethodUsing DestructuringMethod 1: Using an Extra VariableIn this method, we will take the help of an extra variable name “temp” and then we do the followingWe will copy the first element to temp.Copy the second element value to the ... Read More

Advertisements