Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: JavaScript code to convert phone number phrase to actual phone number

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JavaScript code to convert phone number phrase to actual phone number

    I'm required to
    - ask the user for the phone number phrase using a standard HTML form and followed by a
    - java script function to convert the number phrase into actual number
    - the final output must show up without using html input controls


    Been trying to accomplish this using if else statements within the <script> tag but did not succeed.

    Any help would be greatly appreciated.

    Thanks


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default re: JavaScript code to convert phone number phrase to actual phone number

    Moved to other languages.

    JavaScript is not Java.

    --- Update ---

    Moved to other languages.

    JavaScript is not Java.

  3. #3
    Member Ganeprog's Avatar
    Join Date
    Jan 2014
    Location
    Chennai,India
    Posts
    80
    My Mood
    Love
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Default Re: JavaScript code to convert phone number phrase to actual phone number

    hi,

    Please post your coding what you tried then we will continue from that.

    Happy to help you.

    Thanks,

  4. #4
    Junior Member
    Join Date
    Feb 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JavaScript code to convert phone number phrase to actual phone number

    Thanks. Here's what I have so far:

    <!DOCTYPE html>



    <html>

    <head>

    <meta charset="utf-8" />

    <title>JavaScript</title>





    </head>

    <body>

    <form>

    Enter Phone Number: <input type="text" number="phone number"><br>


    </form>

    <script type="text/javascript">



    public class telephone {

    public static int getNumber(char uppercaseLetter)

    if (letter=='G' || letter=='H' || letter== 'I')
    {
    return 4;
    }
    else if (letter=='M' || letter=='N' || letter== 'O')
    {
    return 6;
    }
    else if (letter=='T' || letter=='U' || letter== 'V')
    {
    return 8;
    }
    else if (letter=='J' || letter=='K' || letter== 'L')
    {
    return 5;
    }
    public static void main (String[] args) {
    Scanner input = new Scanner(System.in);
    System.out.print("Enter alphanumeric phone number to convert to all numbers.");

    String phoneNumber = input.nextLine();
    System.out.println(getNumber(letter.charAt(0)));

    }
    }
    </script>
    </body>

    </html>

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: JavaScript code to convert phone number phrase to actual phone number

    Please see Announcements - Other Programming Languages for how to use the code tags and other useful information.

    ...
    <script type="text/javascript">
    ...
    public static void main (String[] args) {
    ....
    I would recommend reading the basics of javascript - in the above code you have mixed java and javascript, which are two separate beasts entirely. Your assignment looks to want to focus your attention on using javascript

  6. #6
    Member Ganeprog's Avatar
    Join Date
    Jan 2014
    Location
    Chennai,India
    Posts
    80
    My Mood
    Love
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Default Re: JavaScript code to convert phone number phrase to actual phone number

    Hi,

    I think you are quiet confused with java and JavaScript. Java and JavaScript is entirely different. K Choose your language and focus clearly as well learn the difference of both.

    Thanks,

Similar Threads

  1. Phone Number Problem
    By digitalsystems in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 5th, 2013, 10:52 AM
  2. phone number generator
    By yuli in forum What's Wrong With My Code?
    Replies: 18
    Last Post: November 4th, 2013, 05:36 PM
  3. phone number generator1
    By yuli in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 4th, 2013, 04:37 PM
  4. need help with phone number program for homework
    By stevolabo in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 23rd, 2012, 07:34 PM