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
Javascript Articles
Page 382 of 534
Converting a proper fraction to mixed fraction - JavaScript
A proper fraction is one where the numerator is smaller than the denominator, represented in p/q form where both p and q are natural numbers. What is a Mixed Fraction? When we divide the numerator (a) of a fraction by its denominator (b), we get a quotient (q) and remainder (r). The mixed fraction form for fraction a/b is: Mixed form: q r b This is pronounced as "q wholes and r by b". Problem Statement We need to write a ...
Read MoreWorking with tag in HTML5
The tag in HTML5 SVG allows you to create multi-sided shapes by defining a series of connected straight lines. It's perfect for creating geometric shapes like triangles, stars, and other polygonal figures. Syntax Key Attributes The points attribute defines the polygon's vertices as coordinate pairs (x, y), separated by spaces or commas. Other common attributes include fill, stroke, and stroke-width. Example: Creating an SVG Star ...
Read MoreImplementing Priority Sort in JavaScript
We are required to write a JavaScript function that takes in two arrays of numbers, second being smaller in size than the first. Our function should return a sorted version of the first array (in increasing order) but put all the elements that are common in both arrays to the front. For example − If the two arrays are − const arr1 = [5, 4, 3, 2, 1]; const arr2 = [2, 3]; Then the output should be − [2, 3, 1, 4, 5] How It Works The priority ...
Read MoreBackward compatibility with HTML5
HTML5 is designed to be backward compatible with existing web browsers. New features build on existing features and allow you to provide fallback content for older browsers. Modern browsers like Safari, Chrome, Firefox, and Opera support many HTML5 features. Even older versions of Internet Explorer have partial support, while mobile browsers on iPhones, iPads, and Android phones provide excellent HTML5 compatibility. Feature Detection with JavaScript Instead of browser detection, use feature detection to check if specific HTML5 features are supported: // Check for Canvas support if (document.createElement('canvas').getContext) { console.log('Canvas is ...
Read MoreFinding mistakes in a string - JavaScript
We are required to write a JavaScript function that takes in two strings. The first string is some mistyped string and the second string is the correct version of this string. We can assume that the two strings we are getting as argument will always have the same length. We have to return the number of mistakes that exist in the first string by comparing it character by character with the correct version. Approach The solution involves iterating through both strings simultaneously and comparing each character at the same position. When characters don't match, we increment our ...
Read MoreIs their a cross-origin attribute in HTML5?
Yes, HTML5 includes the crossorigin attribute. According to the official specification, it's defined as: The crossorigin attribute is a CORS settings attribute. Its purpose is to allow images from third-party sites that allow cross-origin access to be used with canvas. Syntax Supported Values The crossorigin attribute accepts two values: Value Description Credentials Sent? anonymous Performs CORS request without credentials No use-credentials Performs CORS request with credentials Yes Example: Canvas Image Access ...
Read MoreFrequency distribution of elements - JavaScript
We are required to write a JavaScript function that takes a string and returns an object representing the frequency distribution of each character in the string. const str = 'This string will be used to calculate frequency distribution'; We need to return an object that represents the frequency distribution of various characters present in the string. Example Following is the code: const str = 'This string will be used to calculate frequency distribution'; const frequencyDistribution = str => { const map = {}; ...
Read MoreWhat is the usage of and elements? Why they were introduced?
The HTML5 and elements are semantic tags that provide meaningful structure to web content. They improve accessibility for screen readers and help visually impaired users navigate content more effectively. These elements are also beneficial for eBook readers and search engines. The Element The element represents a thematic grouping of content, typically with its own heading. It's used to divide content into distinct sections within a document. Syntax Section Title Section content goes here... Example ...
Read MoreFind distinct elements - JavaScript
We are required to write a JavaScript function that takes in an array of literals, such that some array elements are repeated. We are required to return an array that contains elements that appear only once (not repeated). For example: If the array is: const arr = [9, 5, 6, 8, 7, 7, 1, 1, 1, 1, 1, 9, 8]; Then the output should be: const output = [5, 6]; Using indexOf() and lastIndexOf() The first approach uses indexOf() and lastIndexOf() to check if an element appears only once. If ...
Read MoreAdding HTML5 Validation to Visual Studio
Visual Studio 2012 and later versions include built-in IntelliSense and validation support for HTML5. Visual Studio 2010 had basic IntelliSense support for HTML5, but VS 2012 added corresponding code snippets, making it faster and easier to write HTML5 markup. Enabling HTML5 Validation in Visual Studio Follow these steps to enable HTML5 validation: Launch Visual Studio 2012 (or later). Go to Tools > Options from the menu bar. In the Options dialog, navigate to Text Editor > HTML > Validation. In ...
Read More