Web Development Articles

Page 193 of 801

Sending personalised messages to user using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 316 Views

We need to write a JavaScript function that sends personalized messages based on whether the user is the owner or a regular user. The function takes two parameters: the user name and the owner name. Problem Statement Create a function that compares the user name with the owner name and returns appropriate greetings: If the user is the owner: return "Hello master" If the user is different from owner: return "Hello" followed by the user's name Solution Here's the implementation using a simple conditional statement: const name = 'arnav'; const owner ...

Read More

Reversing the even length words of a string in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 413 Views

We are required to write a JavaScript function that takes in a string and reverses the words in the string that have an even number of characters in them. Let's say the following is our string: const str = 'This is an example string'; We want to reverse the even length words of the above string i.e. reverse the following words: This (4 characters) is (2 characters) an (2 characters) string (6 characters) The word "example" has 7 characters (odd length), so it remains unchanged. Syntax ...

Read More

Numbers and operands to words in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 249 Views

We are required to write a JavaScript function that takes in a string of some mathematical operation and return its literal wording. Problem Converting mathematical expressions like "5 - 8" into readable words like "Five Minus Eight" requires mapping numbers and operators to their text equivalents. Approach We'll create two lookup objects: one for operators and another for numbers. Then parse the input string and convert each part using these mappings. Example Following is the code − const str = '5 - 8'; const convertToWords = (str = '') => { ...

Read More

Differences in two strings in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 527 Views

We are required to write a JavaScript function that takes in two strings and find the number of corresponding dissimilarities in the strings. The corresponding elements will be dissimilar if they are not equal at the same position. Example Strings Let's say the following are our strings: const str1 = 'Hello world!!!'; const str2 = 'Hellp world111'; In this case, we need to compare each character at the same index and count how many positions have different characters. Method 1: Using a For Loop const str1 = 'Hello world!!!'; const str2 ...

Read More

Encrypting censored words using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 324 Views

This tutorial demonstrates how to encrypt or mask censored words in JavaScript by applying specific transformation rules to convert regular text into a masked format. Problem We need to write a JavaScript function that takes in a string and converts it according to the following rules: All words should be in uppercase Every word should end with '!!!!' Any letter 'a' or 'A' should become '@' Any other vowel (E, I, O, U) should become '*' Solution Here's the implementation of the word masking function: const str = 'ban censored words'; ...

Read More

Finding the index of the first repeating character in a string in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 648 Views

We are required to write a JavaScript function that takes in a string and returns the index of the first character that appears twice in the string. If there is no such character then we should return -1. Let's say the following is our string − const str = 'Hello world, how are you'; We need to find the index of the first repeating character. Understanding the Problem In the string "Hello world, how are you", we need to find which character repeats first. The character 'l' appears at index 2 and again ...

Read More

Moving every alphabet forward by 10 places in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 295 Views

Problem We need to write a JavaScript function that takes a string of English alphabets and shifts every letter forward by 10 positions. When a letter goes past 'z', it wraps around to start again at 'a'. Example Following is the code − const str = 'sample string'; const moveStrBy = (num = 10) => { return str => { const calcStr = (ch, code) => String .fromCharCode(code + (ch.charCodeAt(0) - ...

Read More

Column sum of elements of 2-D arrays in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

We have an array of arrays and are required to write a function that takes in this array and returns a new array that represents the sum of corresponding elements of original array. If the original array is: [ [43, 2, 21], [1, 2, 4, 54], [5, 84, 2], [11, 5, 3, 1] ] Then the output should be: [60, 93, 30, 55] This means we add all elements at index 0 (43+1+5+11=60), all elements at index 1 (2+2+84+5=93), ...

Read More

Finding the date at which money deposited equals a specific amount in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 170 Views

When calculating compound interest over time, you may need to determine the exact date when your deposited money will reach a target amount. This problem involves daily compounding at a given annual interest rate. Problem Statement Given an initial deposit amount, a target amount, and an annual interest rate, we need to find the date when the deposited money (with daily compounding) will equal or exceed the target amount. The calculation starts from January 1st, 2021, with interest compounded daily at a rate of p percent divided by 360 days. Solution Approach The solution uses a ...

Read More

Finding smallest number that satisfies some conditions in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 272 Views

We are required to write a JavaScript function that takes in a number as the first argument, say n, and an array of numbers as the second argument. The function should return the smallest n-digit number which is a multiple of all the elements specified in the array. If there exist no such n-digit element then we should return the smallest such element. For example: If the array is − const arr = [12, 4, 5, 10, 9] For both n = 2 and n = 3, we need to find the smallest number ...

Read More
Showing 1921–1930 of 8,010 articles
« Prev 1 191 192 193 194 195 801 Next »
Advertisements