JavaScript Examples

Basic JavaScript – Exercise 06 -Conditional Statements

 32 total views

 32 total views Previous Next Conditional statements in JavaScript uses if-else or switch statement that change the direction of the program in run-time. The conditional statement check certain conditions and then based on the truth value of the condition, execute a block of code. The if-else statements could be nested to make a if-if-else-else or if-else- …

Basic JavaScript – Exercise 06 -Conditional Statements Read More »

Repeat A String

 4 total views

 4 total views Previous Next In JavaScript, there are several in-built functions to manipulate strings. One of them is String.prototype.repeat() function. In this tutorial, you will write a program that will repeat a string for a given number of times. The steps that this program follows is given below: JavaScript function receives an input string and …

Repeat A String Read More »

Find The Largest Number

 9 total views

 9 total views Previous Next In this example, we will receive a two-dimensional array of numbers as input and the JavaScript function will find the largest in each sub-array and return the result in a new array. The program takes following steps to compute the results: Receive an array with many sub-arrays. Set a maximum number …

Find The Largest Number Read More »

Find Longest Word in a String

 30 total views

 30 total views Previous Next In this example, you will create a JavaScript function that will accept a string that contains multiple words and find the longest among those words and display the length of the string. The program takes following steps to find the longest string. Accept the string in a function – findLengthLongest(). Use …

Find Longest Word in a String Read More »

Reverse a String

 12 total views

 12 total views Previous Next In this example, we will create a program using JavaScript and HTML to reverse a given string and display the output. The JavaScript code will accept a string from a HTML textbox control and reverse the string and output the result to a H1 element to display. The step to reverse …

Reverse a String Read More »