Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Prince Varshney
22 articles
How to Create Pong Game in JavaScript?
A Pong game is a two-player paddle game where each player's task is to save the ball from hitting the wall. Whenever player 1 hits the ball at the opponent's wall then player one will receive a point, and similarly, player 2 will get a point if he/she hits the ball at the opponent's wall. In this tutorial, we will create a Pong Game in JavaScript using HTML5 Canvas. Game Controls Before implementing the game, let's understand the controls: Left Player: Use 'Z' key to move up and 'S' key to move down ...
Read MoreHow to design hit the mouse game using HTML, CSS and JavaScript?
In this tutorial, we are going to build the famous hit the mouse game using HTML, CSS, and vanilla JavaScript. Many of you wondering what is Vanilla JavaScript, it is nothing just plain JavaScript written without the use of any libraries. In the hit the mouse game, the player needs to hit the mouse with the hammer in order to earn points and win the game. Approach To design the mouse game, we need to write the code in HTML, CSS, and JavaScript. Step 1 − Firstly, let us look into the HTML part of the code; ...
Read MoreWhat is Unary Plus Operator in JavaScript?
The unary plus operator (+) is a JavaScript operator that converts its operand to a number. Unlike binary plus for addition, the unary plus works on a single value and is primarily used for type conversion from non-numeric values to numbers. Syntax +operand Where operand can be any JavaScript value that you want to convert to a number. Using Unary Plus with Numeric Strings The unary plus operator converts string representations of numbers into actual numbers: const x = ...
Read MoreHow to find the binomial coefficient of two integers using JavaScript?
In this tutorial, we are going to learn how to find the binomial coefficient of two integers using JavaScript. Before learning it we should know what binomial coefficient is and what it refers to. What are Binomial Coefficients? Binomial coefficients refer to the positive integers that occur as coefficients in the binomial theorem. A binomial coefficient C(n, k) can be defined as the coefficient of x^k in the expansion of (1 + x)^n. A binomial coefficient of two numbers n and k signifies the number of combinations of k items that can be selected from a ...
Read MoreHow to find every element that exists in any of two given arrays once using JavaScript?
In this tutorial, we will learn how to find every element that exists in any of two given arrays once. This means creating a new array containing all unique elements from both arrays, with no duplicates. For example, given two arrays: Input const arr1 = [1, 2, 3, 4, 5] const arr2 = [1, 4, 9, 16, 25] Output result = [1, 2, 3, 4, 5, 9, 16, 25] Input const arr1 = ['Deepansh', 'Aditya', 'Rishabh', 'Rishit'] const arr2 = ['Vikrant', 'Rishabh', 'Mohit', 'Rishit'] Output result = ['Deepansh', ...
Read MoreHow to find all elements in a given array except for the first one using JavaScript?
In this tutorial, we will learn how to get all elements from an array except the first one using JavaScript. This is a common operation when you need to remove or skip the first element while processing array data. There are two main approaches to accomplish this task: Using the slice() Method (Recommended) The slice() method creates a shallow copy of a portion of an array. When called with index 1, it returns all elements starting from the second element. Syntax array.slice(startIndex) Example ...
Read MoreHow to get the length of a string in bytes in JavaScript?
In JavaScript, getting the length of a string in bytes is different from getting its character count. A byte is a unit of data that is 8 binary bits long, and while most ASCII characters use 1 byte, Unicode characters like emojis or special symbols may use multiple bytes. Here are examples of strings and their byte lengths: Examples: "JavaScript" → 10 bytes (each ASCII character = 1 byte) "20€" → 5 bytes (€ symbol uses 3 bytes in UTF-8) "Tutorials Point" → 15 bytes There ...
Read MoreHow to replace line breaks with using JavaScript?
In this tutorial, we will learn how to replace line breaks in JavaScript strings with HTML tags. This is commonly needed when converting plain text with line breaks to HTML format for proper display in web pages. Using String replace() Method and RegEx The replace() method with regular expressions is the most comprehensive approach as it handles all types of line breaks including \r (Windows), (Unix/Linux), and \r (Mac). Syntax sentence.replace(/(?:\r|\r|)/g, ""); Here sentence is the string with line breaks, and the regular expression matches all three line break formats. ...
Read MoreWhat is JavaScript Error Constructor?
A JavaScript constructor is a function that creates and initializes an object instance of a class. A constructor is used to create a new object and set values for existing object properties. The Error() constructor in JavaScript is used to create new error objects. Error objects are thrown when runtime errors occur. The Error object can also be used as a base object for user-defined exceptions. Syntax Following is the syntax for an Error() constructor: new Error() new Error(message) new Error(message, options) new Error(message, fileName) new Error(message, fileName, lineNumber) Parameters The Error() constructor ...
Read MoreHow to print colored text in the console using JavaScript?
In this article, we will learn how to add colors to the text and print them in the console window of JavaScript. In the original, all the data printed in the console is of black color no other color is reflected in the console but here we are going to add some special characters with text to make our console window look more colorful. There are some special codes that help change in color of the output in the console window and these codes are known as ANSI escape codes. By adding these codes in the console.log() method we ...
Read More