Javascript Articles

Page 381 of 534

HTML5 IndexedDB Example

Sravani S
Sravani S
Updated on 15-Mar-2026 280 Views

IndexedDB is a powerful client-side database API that allows you to store structured data in the browser. Here's how to add data to an IndexedDB database. Setting Up IndexedDB Before adding data, you need to open a database and create an object store: let db; // Open IndexedDB database const request = indexedDB.open("EmployeeDB", 1); request.onupgradeneeded = function(event) { db = event.target.result; const objectStore = db.createObjectStore("employee", { keyPath: "id" }); console.log("Database setup complete"); }; request.onsuccess = function(event) { ...

Read More

Returning poker pair cards - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 202 Views

We are required to write a function that takes in an array of exactly five elements representing the five cards of a poker player drawn randomly. If the five cards contain at least one pair, our function should return the card number of the highest pair (trivial if there only exists a single pair). Else our function should return false. For example: If the array is − const arr = ['A', 'Q', '3', 'A', 'Q']; Then our function should return − 'A' (as 'A' > 'Q' in card games) Card Ranking System ...

Read More

Example of createSignalingChannel() in HTML5

Vrundesha Joshi
Vrundesha Joshi
Updated on 15-Mar-2026 194 Views

WebRTC enables peer-to-peer communication between browsers, requiring signaling for network information, session control, and media exchange. Developers can implement signaling using various protocols like SIP, XMPP, or custom two-way communication channels. What is createSignalingChannel()? The createSignalingChannel() function establishes a communication channel between peers to exchange connection information before direct peer-to-peer communication begins. This is essential for WebRTC setup. Complete Example var signalingChannel = createSignalingChannel(); var pc; var configuration = { iceServers: [{ urls: 'stun:stun.l.google.com:19302' }] }; // run start(true) to initiate a call function start(isCaller) { ...

Read More

Counting the number of redundant characters in a string - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 321 Views

We are required to write a JavaScript function that takes in a string and returns the count of redundant characters in the string. A redundant character is any character that appears more than once, where all duplicate occurrences (except the last one) are considered redundant. For example − If the string is − const str = 'abcde' Then the output should be 0 because each character appears only once. If the string is − const str = 'aaacbfsc'; Then the output should be 3 because 'a' appears 3 times (2 ...

Read More

Blending two images with HTML5 canvas

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 2K+ Views

To blend two images using HTML5 canvas, you need to manipulate pixel data from both images and combine them in equal proportions (50-50). This technique uses the canvas getImageData() and putImageData() methods. HTML Structure First, set up the HTML elements with the images and canvas: Blended image: window.onload = function () { var myImg1 = document.getElementById('myImg1'); var myImg2 = document.getElementById('myImg2'); var myCanvas = document.getElementById("canvas"); var ctx = myCanvas.getContext("2d"); // ...

Read More

Sorting digits of all the number of array - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 834 Views

We are required to write a JavaScript function that takes in an array of numbers and reorders the digits of all the numbers internally in a specific order (let's say in ascending order for the sake of this problem). For example − If the array is − const arr = [543, 65, 343, 75, 567, 878, 87]; Then the output should be − const output = [345, 56, 334, 57, 567, 788, 78]; Approach The solution involves converting each number to a string, splitting it into individual digits, sorting those ...

Read More

How to display rupee symbol in HTML

Govinda Sai
Govinda Sai
Updated on 15-Mar-2026 2K+ Views

The Indian rupee symbol (₹) can be displayed in HTML using several methods. Here are the most reliable approaches to ensure proper display across different browsers. Using HTML Entity Code The most straightforward method is using the HTML entity code for the rupee symbol: Rupee Symbol Example Price: ₹500 Amount: ₹1000 Price: ₹500 Amount: ₹1000 Using Font Awesome Icons Font Awesome provides a reliable cross-browser solution with the rupee icon: ...

Read More

Joining two strings with two words at a time - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 214 Views

We are required to write a JavaScript function that takes in two strings, creates and returns a new string with first two characters of first string, next two characters of second string, then first, then second and so on. For example: If the strings are: const str1 = 'Hello world'; const str2 = 'How are you btw'; Then the output should be: 'HeHollw o arwoe rlyodu btw' Approach The algorithm alternates between the two strings, taking two characters at a time. When one string is exhausted, it appends the ...

Read More

Composition attribute in HTML5 Canvas?

Jennifer Nicholas
Jennifer Nicholas
Updated on 15-Mar-2026 298 Views

HTML5 Canvas provides the globalCompositeOperation property that controls how new shapes are drawn on top of existing shapes. This property determines the compositing behavior when overlapping occurs. Syntax context.globalCompositeOperation = "composite-operation"; Available Composite Operations The globalCompositeOperation property accepts several values that define different blending modes: source-over (default): New shapes are drawn on top source-in: New shapes are drawn only where they overlap existing content source-out: New shapes are drawn only where they don't overlap destination-over: New shapes are drawn behind existing content lighter: Colors are added together for brighter results copy: Only ...

Read More

How to draw large font on HTML5 Canvas?

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

To draw large font text on HTML5 Canvas, you need to set the font size using the font property and use fillText() or strokeText() methods to render the text. Basic Syntax context.font = "size family"; context.fillText(text, x, y); context.strokeText(text, x, y); Example: Drawing Large Text Large Font Canvas var myCanvas = document.getElementById("myCanvas"); var ...

Read More
Showing 3801–3810 of 5,340 articles
« Prev 1 379 380 381 382 383 534 Next »
Advertisements