• We just launched and are currently in beta. Join us as we build and grow the community.

JavaScript - Simple Money Currency Converter

hghgh

Mockery Master
H Rep
0
0
0
Rep
0
H Vouches
0
0
0
Vouches
0
Posts
89
Likes
43
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
In this tutorial we will create a Simple Money Currency Converter using JavaScript. The code can convert any currency when the user input some amount and click the convert button. The code use onclick() to initiate a switch function in order to convert the given amount base on the selected currency. This is a user-friendly program feel free to modify it.

We will use JavaScript to add some new feature to the website interface by actually written into an HTML page. It is what gives your page a different interactive elements and animation that engage a user.

Getting Started:

This is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.

The Main Interface

This code contains the interface of the application. To create this just write these block of code inside the text editor and save this as index.html.
  1. <!DOCTYPE html>
  2. <!DOCTYPE html>
  3. <html

    lang

    =

    "en"

    >
  4. <head

    >
  5. <link

    rel

    =

    "stylesheet"

    type

    =

    "text/css"

    href

    =

    "css/bootstrap.css"

    /

    >
  6. <meta

    charset

    =

    "UTF-8"

    name

    =

    "viewport"

    content

    =

    "width=device-width, initial-scale=1"

    /

    >
  7. </

    head

    >
  8. <body

    >
  9. <nav class

    =

    "navbar navbar-default"

    >
  10. <div

    class

    =

    "container-fluid"

    >
  11. <a

    class

    =

    "navbar-brand"

    href

    =

    "https://sourcecodester.com"

    >

    Sourcecodester</

    a

    >
  12. </

    div

    >
  13. </

    nav>
  14. <div

    class

    =

    "col-md-3"

    ></

    div

    >
  15. <div

    class

    =

    "col-md-6 well"

    >
  16. <h3

    class

    =

    "text-primary"

    >

    JavaScript - Simple Money Currency Converter</

    h3

    >
  17. <hr

    style

    =

    "border-top:1px dotted #ccc;"

    >
  18. <div

    class

    =

    "col-md-3"

    ></

    div

    >
  19. <div

    class

    =

    "col-md-6"

    >
  20. <div

    class

    =

    "form-group"

    >
  21. <label

    >

    Enter an amount</

    label

    >
  22. <select

    class

    =

    "form-control"

    id

    =

    "currency"

    style

    =

    "width:30%;"

    >
  23. <option

    value

    =

    "Dollar"

    >

    Dollar</

    option

    >
  24. <option

    value

    =

    "Pound"

    >

    Pound</

    option

    >
  25. <option

    value

    =

    "Euro"

    >

    Euro</

    option

    >
  26. <option

    value

    =

    "Yen"

    >

    Yen</

    option

    >
  27. <option

    value

    =

    "Yuan"

    >

    Yuan</

    option

    >
  28. </

    select

    >
  29. <br

    /

    >
  30. <input

    type

    =

    "number"

    class

    =

    "form-control"

    id

    =

    "amount"

    /

    >
  31. </

    div

    >
  32. <center

    ><button

    class

    =

    "btn btn-primary"

    onclick

    =

    "convert();"

    >

    Convert</

    button

    ></

    center

    >
  33. <br

    /

    >
  34. <div

    class

    =

    "form-group"

    >
  35. <label

    >

    Philippine Peso</

    label

    >
  36. <input

    type

    =

    "number"

    class

    =

    "form-control"

    id

    =

    "result"

    readonly

    =

    "readonly"

    /

    >
  37. </

    div

    >
  38. </

    div

    >
  39. </

    div

    >
  40. </

    body

    >
  41. <script

    src

    =

    "js/script.js"

    ></

    script

    >
  42. </

    html

    >

Creating the Script

This code contains the script of the application. This code will convert the currency when the button is clicked. To do this just copy and write these block of codes as shown below inside the text editor and save it as script.js inside the js directory
  1. function

    convert(

    )

    {
  2. var

    amount=

    document.getElementById

    (

    "amount"

    )

    .value

    ;
  3. var

    currency=

    document.getElementById

    (

    "currency"

    )

    .value

    ;
  4. if

    (

    amount ==

    ""

    )

    {
  5. alert(

    'Please enter something first'

    )

    ;
  6. }

    else

    {
  7. switch

    (

    currency)

    {
  8. case

    "Dollar"

    :
  9. document.getElementById

    (

    "result"

    )

    .value

    =

    amount *

    51.89

    ;
  10. break

    ;

  11. case

    "Pound"

    :
  12. document.getElementById

    (

    "result"

    )

    .value

    =

    amount *

    72.39

    ;
  13. break

    ;

  14. case

    "Euro"

    :
  15. document.getElementById

    (

    "result"

    )

    .value

    =

    amount *

    63.84

    ;
  16. break

    ;

  17. case

    "Yen"

    :
  18. document.getElementById

    (

    "result"

    )

    .value

    =

    amount *

    0.49

    ;
  19. break

    ;

  20. case

    "Yuan"

    :
  21. document.getElementById

    (

    "result"

    )

    .value

    =

    x *

    8.20

    ;
  22. break

    ;
  23. }
  24. }
  25. }

There you have it we successfully created a Simple Money Currency Converter using JavaScript. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!


Download
You must upgrade your account or reply in the thread to view hidden text.
 

452,292

323,348

323,357

Top