JavaScript - Simple Money Currency Converter
Submitted by razormist on Sunday, June 9, 2019 - 20:17.
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.
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!
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.- <!DOCTYPE html>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
- <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
- </head>
- <body>
- <nav class="navbar navbar-default">
- <div class="container-fluid">
- </div>
- </nav>
- <div class="col-md-6 well">
- <hr style="border-top:1px dotted #ccc;">
- <div class="col-md-6">
- <div class="form-group">
- <select class="form-control" id="currency" style="width:30%;">
- </select>
- <br />
- <input type="number" class="form-control" id="amount"/>
- </div>
- <br />
- <div class="form-group">
- <input type="number" class="form-control" id="result" readonly="readonly"/>
- </div>
- </div>
- </div>
- </body>
- </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- function convert(){
- var amount=document.getElementById("amount").value;
- var currency=document.getElementById("currency").value;
- if(amount == ""){
- alert('Please enter something first');
- }else{
- switch(currency){
- case "Dollar":
- document.getElementById("result").value = amount * 51.89;
- break;
- case "Pound":
- document.getElementById("result").value = amount * 72.39;
- break;
- case "Euro":
- document.getElementById("result").value = amount * 63.84;
- break;
- case "Yen":
- document.getElementById("result").value = amount * 0.49;
- break;
- case "Yuan":
- document.getElementById("result").value = x * 8.20;
- break;
- }
- }
- }
Add new comment
- 198 views