Part1. Create simple currency app running using NODE. Part 2. Add another dropdo
ID: 3869329 • Letter: P
Question
Part1. Create simple currency app running using NODE.
Part2. Add another dropdown box to the form in index.hbs so the user can select a convert from currency, and a convert to currency. Add code to your app to compute the correct conversion, and display it on the result page, including the from and to currencies. You can use approximate exchange rates. XE.com has exchange rates.
Make sure your app doesn't crash if the user selects the same currency for both dropdown boxes. ( use some client-side JavaScript to display a warning before the user submits the form.)
Part 3. Use your own images and styles; adjust the way the pages are laid out.
Explanation / Answer
Sample code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Dollar Converter</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script>
var rates = {
"EUR" : 0.934,
"GBP" : 0.791,
"INR" : 64.659,
"AUD" : 1.326
};
$(function(){
// Add your code here
convertCurrecy();
});
function isNumber(evt) {
evt = (evt) ? evt : window.event;
var charCode = (evt.which) ? evt.which : evt.keyCode;
console.log(charCode);
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
alert('Numbers only allowed to type');
return false;
}
return true;
}
function convertCurrecy(){
var amt = document.getElementById('dollar').value;
var currId = document.getElementById('currency').value;
var convertAmt = amt * rates[currId];
document.getElementById("amount").innerHTML = convertAmt;
return true;
}
</script>
</head>
<body>
<input type="text" name="dollar" id="dollar" value="0" /> Dollar = <span id="amount">0</span>
<select id="currency">
<option value="EUR">EUR</option>
<option value="GBP">GBP</option>
<option value="INR">INR</option>
<option value="AUD">AUD</option>
</select>
</body>
</html>
Note:
.val() can be used on a <select> element to get the value of the selected option.
.val() can be used only for jquery not in javascript. document.getElementById('dollar').value; this would be used to get the value of selected option.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.