Solve using only Javascript loops...

Solve using only Javascript loops...

Write a JavaScript code, 1) to find a number of unique letters in string. (Eg. if keyword is unique, Unique count will be '4')

2) so that numbers appear in following format,

    1
   1 2
  1 2 3 
 1 2 3 4
1 2 3 4 5
 1 2 3 4
  1 2 3 
   1 2
    1

for n=5. Input 'n' value from user.

3) to create a redirection script based on day of the week.

4) that reads the date of a day in one textbox, the month in a second textbox and the year in a third textbox. After submitting the form, it should display the complete date, including the correct extension on the day number ('st', 'nd', 'rd' or 'th'). Example : 2 April 1999 will produce: 'Today is 2nd of April, 1999.'

View Answers

October 21, 2010 at 5:31 PM

Hi Friend,

Try the following code:

1)

<script>
function code(n, digits, padChar) {
    n = n.toString();
    while (n.length < digits) {
        n = padChar + n;
    }
    return n;
}
    var str = window.prompt("Enter String");
    var array = [];
    var totalCount;
    var count=0;

    for(var i = 0; i < str.length; i++){
        if(!array[str[i]]) {
            array[str[i]] = 1;
        } else {
            array[str[i]] += 1;
        }
    }
    sortedArray = [];
    for(var i in array){
        sortedArray.push(code(i.charCodeAt(0), 5, '0'));
    }
    sortedArray.sort();
    for(i = 0; i < sortedArray.length; i++){
        count++;
        }
        document.write("Number of unique letters are: "+count);
</script>

Thanks


October 21, 2010 at 5:42 PM

Hi Friend,

Try the following code:

4)

<script>
function number(value){
         hunRem = value % 100;
         tenRem = value % 10;
        if (hunRem - tenRem == 10) {
            return "th";
        }
        switch (tenRem) {
        case 1:
            return "st";
        case 2:
            return "nd";
        case 3:
            return "rd";
        default:
            return "th";
        }
    }
    function display(){
    var day=document.form.day.value;
    var mon=document.form.month.value;
    var year=document.form.year.value;

    document.write("Today is "+day+number(day)+" of "+mon+", "+year);
    }
</script>

<form name="form">
<table>
<tr><td>Enter Date of a day:</td><td><input type="text" name="day"></td></tr>
<tr><td>Enter month:</td><td><input type="text" name="month"></td></tr>
<tr><td>Enter year:</td><td><input type="text" name="year"></td></tr>
<tr><td><input type="button" onclick="display();" value="Submit"></td></tr>
</table>
</form>

Thanks


November 27, 2010 at 10:59 AM


November 27, 2010 at 10:59 AM


November 27, 2010 at 11:04 AM

print("code sample");









Related Tutorials/Questions & Answers:
Solve using only Javascript loops...
Solve using only Javascript loops...  Write a JavaScript code, 1) to find a number of unique letters in string. (Eg. if keyword is unique, Unique count will be '4') 2) so that numbers appear in following format, 1 1 2
enabling and disabling a hyperlinks using javascript only
enabling and disabling a hyperlinks using javascript only  Hi! can... be enabled.And when the link is enabled only the page 2.jsp should be displayed...="javaScript" type="text/javascript" src="calendar.js"> function disableLink
Advertisements
enabling and disabling a hyperlinks using javascript only
enabling and disabling a hyperlinks using javascript only  Hi! Anyone.... Question 2: Is there a solution using Java script only to achieve the problem... Question 2: Is there a solution using Java script only to achieve the problem
Javascript loops
Javascript loops  Write a JavaScript code, - for guessing any number between 1 to 20. run the loop till you not get correct number. Use prompt... the following code: <SCRIPT LANGUAGE="JavaScript"> var guess; var rno=Math.round
Java reverse words in a string using only loops
Java reverse words in a string using only loops In this tutorial, you will learn how to reverse words in a string without using any inbuilt methods like split() etc, StringTokenizer functiom or any extra ordinary function Only loops
displaying a calendar of only current month in jsp on webpage using javascript
displaying a calendar of only current month in jsp on webpage using javascript  how can we display a calendar of only current month in jsp on webpage using javascript
Use javascript loops..
Use javascript loops..  Write a Javascript code to create a redirection script based on day of the week
Use javascript loops..
Use javascript loops..  Write a JavaScript code to find a number of unique letters in string. (Eg. if keyword is Tajmahal, Tajmahal count will be '5' , it only takes these letters T,j,m,h,l , not taken the letter a because
Use javascript loops..
Use javascript loops..  Write a Javascript code, so that numbers...--){ document.write(" "); for(var k=q; k>=1;k--){ document.write(" "); } for(var j=1;j<...;"); q++; } document.write("</center>"); </script> ThanksADS
pattern-using loops
pattern-using loops  Write a program that displays the following pattern ... (use nested loops) * ** * ** * ** *   the correct pattren
Using Nested loops
Using Nested loops  How to use nested loops in java when I want to print the 10 multiples of numbers 2 to 15(in multiplication table)   public class MultiplicationTable{ public static void main(String[] args) { int
read string - using loops in Java
read string - using loops in Java  Write a program to read a string composed of an unknown number of words, then count the number of words in the string, and Display the longest and shortest words, with first letter Uppercase
JavaScript Loops Function
JavaScript Loops Types: In Java programming language a loop is a language... a function or method calls itself). JavaScript provides for, while, do-while, and foreach loop. Following examples will help you to learn loops:ADS_TO_REPLACE_1
print 100 numbers using loops
print 100 numbers using loops  how to print from 1 to 100 using for loop ?   Hi Friend, You can use the following code:ADS_TO_REPLACE_1 class Loop{ public static void main(String[] args){ for(int i=1;i<
print rectangle triangle with ?*? using loops
print rectangle triangle with ?*? using loops   * * * * * * i want print like this.what is the code?   import java.lang.*; class Traingles { public static void main(String args[]) { for(int i=1;i<=5
Loops
Loops  ï??Using for loops, Write a program to simulate a clock countdown. The program prompts the user to enter the number of seconds, displays a message at every second, and terminates when the time expires. Use method
loops
loops  I need the program output 55555 4444 333 22 1 like this by using for loop and if condition only
I need to output number diamond using nested for loops.
I need to output number diamond using nested for loops.  How to i output this using nested for loops 1 131 13531 1357531 135797531 1357531 13531 131 1
delete an entry using JavaScript
delete an entry using JavaScript  How to delete an entry using JavaScript
Date object using JavaScript
Date object using JavaScript  What's the Date object using JavaScript
Java repeat string without using loops
Java repeat string without using loops In this section, you will learn how to repeat string without using for loops. The given example accepts the number... using while loop or any other control statements. Example:ADS_TO_REPLACE_1
using for loop in javascript
using for loop in javascript  How to use for loop in JavaScript
Loops
Loops  by using drjava q1.Write code that uses nested loops to print the following patterns: Pattern1: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6 Pattern 2: 1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1 q2.Write code
print a-z, A-Z with exact order using loops
print a-z, A-Z with exact order using loops  how to print from a-z, A-Z with exact order using for loop? Thanks for all concern
write program have product - using loops
write program have product - using loops  Write a program for a grocery that reads products data and determine and display the product that has the highest price and the average price. A product has three pieces of data: id (int
Loops
Loops  Write code that uses nested loops to print the following patterns: Pattern1: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6 Pattern 2: 1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1
Loops
Loops  Write code that uses nested loops to print the following patterns: Pattern1: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6 Pattern 2: 1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1
maximize an image using javaScript
maximize an image using javaScript  Write the code to maximize an image using javaScript
xls to js using javascript
xls to js using javascript  ![how can we convert a xls file in js file using javascript][1
timer using javascript
timer using javascript  How to display timer on HTML page using JavaScript
send mail using JavaScript
send mail using JavaScript  How can we send mail using JavaScript?   Hi friends, You can not send email directly using JavaScript. But you can use JavaScript to execute a client side email program send the email using
loops
loops  how to get the sum of 10 number using a loop
loops
loops  how to use for loop and while loop in java?/ how to write a code using for or while loop
How can we solve this puzzle using java ?
How can we solve this puzzle using java ?  Sachin likes sweets a lot. So, he goes to a market of sweets. There is a row of sweet stalls. Every sweet... of those stalls need to be contiguous. He also decided to buy only 1 kg of sweets from
How to shift and unshift using JavaScript?
How to shift and unshift using JavaScript?  How to shift and unshift using JavaScript
Solve it
Solve it  How to calculate the value which contains oparator and operand both using command line argument
convert numbers to strings using JavaScript
convert numbers to strings using JavaScript  How to convert numbers to strings using JavaScript
read and write a file using javascript
read and write a file using javascript  How to read and write a file using javascript
Math Constants and Functions using JavaScript
Math Constants and Functions using JavaScript  What's Math Constants and Functions using JavaScript
associate functions with objects using JavaScript
associate functions with objects using JavaScript  How to associate functions with objects using JavaScript
set the focus on an element using Javascript
set the focus on an element using Javascript  How to set the focus on an element using Javascript
checkboxes set to true using JavaScript
checkboxes set to true using JavaScript  To set all checkboxes to true using JavaScript
validate radio button using javascript
validate radio button using javascript  validate radio button using javascript
how to print HTML using javascript or Jquery
how to print HTML using javascript or Jquery  is there any way to print a document(created using Html and javascript) without using window.print... window.print but this required to enable pop-up and work only in firefox. and I have also
solve this
solve this   Create a student class. The student object should have.... Retrieval and printing of data should be done both using normal iteration and by using enhanced for loop
Changing background color using JavaScript
Changing background color using JavaScript  Hi Sir Is there any way to change the background color using JavaScript ? Please mention code with your answer.   Hello Friend Pass the element & color in the given
javascript date validation using regex
javascript date validation using regex  Hi, I want to validate the date using javascript. Please help.   <html> <head> <title>Validating Date format</title> <script type="text/javascript">
How to make session control using only JSP programming language
How to make session control using only JSP programming language  Could i do Controlling session using only JSP programming language without using anylanguage
how to give validation using javascript in swing
how to give validation using javascript in swing   how to give validation using javascript in swing....... can somebody give code for username and password validation using javscript and swing
How to write a search functionality using javascript/jquery
How to write a search functionality using javascript/jquery   How to write a search functionality using javascript/jquery for ex: im searching "s" names it wil display "s" names

Ads