Javascript Articles

Page 376 of 534

Neutralisation of strings - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 277 Views

In JavaScript, string neutralisation involves evaluating a string containing only '+' and '-' characters to determine the overall sign. The concept is based on mathematical sign multiplication: like signs produce '+', unlike signs produce '-'. How Neutralisation Works The neutralisation follows these rules: ++ results in + (positive × positive = positive) -- results in + (negative × negative = positive) +- or -+ results in - (positive × negative = negative) Example String Let's work with the following string: const str = '+++-+-++---+-+--+-'; Implementation Here's how to implement ...

Read More

Play video on canvas and preserve the last frame/image on HTML5 Canvas

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 15-Mar-2026 348 Views

You can play a video on an HTML5 canvas and preserve the last frame by continuously drawing the video frames onto the canvas. When the video ends, the last drawn frame remains visible on the canvas. HTML Structure First, create the HTML elements for the video and canvas: Your browser does not support the video tag. JavaScript Implementation Here's the corrected code to play video on canvas and preserve the last frame: ...

Read More

Reverse only the odd length words - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 569 Views

We are required to write a JavaScript function that takes in a string and reverses the words in the string that have an odd number of characters in them. Any substring in the string qualifies to be a word, if either it is encapsulated by two spaces on either ends or present at the end or beginning and followed or preceded by a space. Let's say the following is our string: const str = 'hello beautiful people'; The odd length words are: hello (5 characters - odd) beautiful (9 characters - odd) ...

Read More

How can I write a form that assists my browser's auto-complete feature?

Krantik Chavan
Krantik Chavan
Updated on 15-Mar-2026 178 Views

HTML forms can leverage browser autocomplete to improve user experience by providing appropriate hints about what data each field expects. The autocomplete attribute tells browsers how to pre-fill form fields based on previously entered data. The autocomplete Attribute The HTML5 specification defines the autocomplete attribute to help browsers understand field purposes. When set to "on", browsers use heuristics based on field names, DOM position, and other factors to suggest appropriate values. Common Autocomplete Values Use specific autocomplete values to provide clear hints to browsers: Field Name Meaning "name" Full name ...

Read More

Return index of first repeating character in a string - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 283 Views

We are required to write a JavaScript function that takes in a string and returns the index of first character that appears twice in the string. If there is no such character then we should return -1. Following is our string: const str = 'Hello world, how are you'; Example Following is the code: const str = 'Hello world, how are you'; const firstRepeating = str => { const map = new Map(); for(let i = 0; i < str.length; i++){ ...

Read More

Draw Lines with easelJS using Ticker in HTML

Samual Sam
Samual Sam
Updated on 15-Mar-2026 400 Views

EaselJS is a JavaScript library that simplifies working with the HTML5 Canvas element. It's particularly useful for creating interactive graphics, animations, and games in web browsers. To draw animated lines using the Ticker method in HTML with EaselJS, you need to set up a stage, create shape objects, and use the Ticker to continuously update the canvas. Basic Setup First, create the HTML structure with a canvas element and include the EaselJS library: EaselJS Line Drawing ...

Read More

Valid triangle edges - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 521 Views

In geometry, three lines can form a triangle only if they satisfy the triangle inequality theorem: the sum of any two sides must be greater than the third side. This fundamental rule ensures that the three sides can actually connect to form a closed triangle. For example, if three lines have lengths 4, 9, and 3, they cannot form a triangle because 4 + 3 = 7, which is less than 9. At least one side would be too long to connect with the other two. Triangle Inequality Theorem For sides with lengths a, b, and c ...

Read More

canvas.style.display = "block" not working in HTML5

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 322 Views

When working with HTML5 canvas elements, you might encounter issues where setting canvas.style.display = "block" doesn't work as expected. This usually happens due to timing issues, incorrect element selection, or CSS conflicts. Common Problem The most frequent issue occurs when trying to modify the canvas display style before the DOM is fully loaded or when the canvas element reference is incorrect. Show Canvas function showCanvas() { let canvas = document.getElementById("myCanvas"); canvas.style.display = "block"; console.log("Canvas display set to:", canvas.style.display); } ...

Read More

Absolute sum of array elements - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 878 Views

We are required to write a JavaScript function that takes in an array with both positive and negative numbers and returns the absolute sum of all the elements of the array. We are required to do this without taking help of any inbuilt library function. For example: If the array is − const arr = [1, -5, -34, -5, 2, 5, 6]; Then the output should be − 58 Understanding Absolute Sum The absolute sum means we convert all negative numbers to positive and then add all elements. For ...

Read More

To "user-scalable=no" or not to "user-scalable=no" in HTML5

Rishi Rathor
Rishi Rathor
Updated on 15-Mar-2026 324 Views

The user-scalable=no viewport meta tag prevents users from zooming on mobile devices. While it creates app-like experiences, it raises important accessibility concerns that developers must consider. What is user-scalable=no? The user-scalable property is part of the viewport meta tag that controls whether users can zoom in and out on mobile devices. When to Use user-scalable=no Consider using user-scalable=no only when creating web applications that need to mimic native mobile app behavior: App-like Interface ...

Read More
Showing 3751–3760 of 5,340 articles
« Prev 1 374 375 376 377 378 534 Next »
Advertisements