-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
46 lines (41 loc) · 1.53 KB
/
popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
document.addEventListener('DOMContentLoaded', function() {
var convertButton = document.getElementById('convert-button');
var input = document.getElementById('amount-input');
var resultElement = document.getElementById('result');
var dollarIcon = document.getElementById('dollar-icon');
var inrIcon = document.getElementById('inr-icon');
var inputGroup = document.getElementById('input-group');
dollarIcon.addEventListener('click', function() {
inputGroup.style.display = 'block';
input.focus();
input.placeholder = 'Enter amount in Dollars';
});
inrIcon.addEventListener('click', function() {
inputGroup.style.display = 'block';
input.focus();
input.placeholder = 'Enter amount in INR';
});
convertButton.addEventListener('click', function() {
convertAmount();
});
input.addEventListener('keypress', function(event) {
if (event.keyCode === 13) {
convertAmount();
}
});
function convertAmount() {
var amount = parseFloat(input.value);
if (!isNaN(amount)) {
if (input.placeholder === 'Enter amount in Dollars') {
var dollars = amount;
var rupees = dollars * 82.61;
resultElement.innerText = dollars.toFixed(2) + ' USD = ' + rupees.toFixed(2) + ' INR';
}
else if (input.placeholder === 'Enter amount in INR') {
var rupees = amount;
var dollars = rupees * 0.012;
resultElement.innerText = rupees.toFixed(2) + ' INR = ' + dollars.toFixed(2) + ' USD';
}
}
}
});