1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Help with simple number translator.

Discussion in 'JavaScript' started by Chris Toa, Jul 1, 2021.

  1. #1
    Hi there, I'm looking for some guidance as a beginner in JavaScript for a school project.
    Below are the specifications of the software:

    The software will translate into French or German integer numbers from 1 to 30 inclusive.
    The program should ask:
    1) What number to translate
    • The user should type digits
    • If the user doesn’t type digits, the following message must be displayed “Please use digits” and the program must end
    • If the user doesn’t type a number between 1 and 30, the following message must be displayed “Please type an integer number between 1 and 30” and the program must end
    2) What is the output language
    • The user should type German or French (case is insensitive)
    • If the user doesn’t type German or French, the following message must be displayed “only French or German is allowed” and the program must end
    3) Display the result in the following syntax: “The translation is XXX”
    4) Wait for any key to exit
    upload_2021-7-1_23-5-39.png
    As shown above, it is going to be a console based program, there won’t be any graphical user interface.

    T.I.A
    Chris.
     
    Chris Toa, Jul 1, 2021 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #2
    First up, thanks for letting us know that this is a school project. We'll point you in the right direction, check your work but we won't do it for you because that defeats the purpose.

    Secondly, good to have some Kiwi company on here.

    Third, get an online place to test and share your code, jsfiddle is good, I like codepen too.

    When the user types there are two ways to catch what they've typed.
    1. <input type="text" onkeyup="myFunction()">
      but that sucks and I'd mark you down for using it. That said, I'm not your teacher.
    2. document.getElementById('digit').addEventListener('keyup', logKey);
      listeners are the right way to catch the keystroke and call a javascript function - or use an anonymous function
    As for the translation, I guess you just have an array for German and another for French and use the input number as the key to the array.
     
    sarahk, Jul 1, 2021 IP
  3. FrogeHost

    FrogeHost Member

    Messages:
    39
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    33
    #3
    What do you have so far? Post it here and we'll help you figure out what to do next.
     
    FrogeHost, Jul 2, 2021 IP