Questions JavaScript
1. Write a JavaScript function that reverse a number.
Sample Data and output:
Example x = 32243;
Expected Output : 34223
2. Write a JavaScript function that returns a passed string with letters in
alphabetical order.
Example string : 'webmaster'
Expected Output : 'abeemrstw'
Note: Assume punctuation and numbers symbols are not included in the passed
string..
3. Write a JavaScript function that accepts a string as a parameter and counts the
number of vowels within the string.
Note : As the letter 'y' can be regarded as both a vowel and a consonant, we do
not count 'y' as vowel here.
Sample Data and output:
Example string : 'The quick brown fox'
Expected Output : 5
4. Write a JavaScript function that accepts a string as a parameter and converts
the first letter of each word of the string in upper case.
Example string : 'the quick brown fox'
Expected Output : 'The Quick Brown Fox '
5. Write a JavaScript program to get the current date.
Expected Output :
mm-dd-yyyy, mm/dd/yyyy or dd-mm-yyyy, dd/mm/yyyy
6. Write a JavaScript program that accept two integers and display the larger
7. Write a JavaScript conditional statement to find the sign of product of three
numbers. Display an alert box
with the specified sign.
Sample numbers : 3, -7, 2
Output : The sign is -
8. Write a JavaScript function to clone an array.
Test Data :
document.write(array_Clone([1, 2, 4, 0]));
document.write(array_Clone([1, 2, [4, 0]]));
[1, 2, 4, 0]
[1, 2, [4, 0]]
9. Write a simple JavaScript program to join all elements of the following array
into a string.
Expected Output :
"Red,Green,White,Black"
"Red,Green,White,Black"
"Red+Green+White+Black"
10. Write a JavaScript program to sort the items of an array.
Sample array : var arr1 = [ 3, 8, 7, 6, 5, -4, 3, 2, 1 ];
Sample Output : -4,-3,1,2,3,5,6,7,8
11. Write a JavaScript conditional statement to sort three numbers. Display an
alert box to show the result.
Sample numbers : 3, -7, 2
Output : The sign is -
12. Write a JavaScript program to calculate age.
13. Write a JavaScript function to check whether a string is blank or not.
14. Write a JavaScript function to remove specified number of characters from a
String.
15. Write a JavaScript function for Factorial, Prime number, Fibonacci Series for a
given number.