Skip to content

Commit

Permalink
Fx converter
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveyEke committed Feb 27, 2024
1 parent ec73845 commit 33a5b70
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<!DOCTYPE html>
<html lang="en">
<head>
<style>
body{
margin: 200px;
text-align: center;
background-color: aqua;
}
</style>
<title>Currency Exchange</title>

<script>
document.addEventListener('DOMContentLoaded',function(){

document.querySelector('form').onsubmit = function(){


fetch('https://v6.exchangerate-api.com/v6/a840ec47274bed9def64fc2a/latest/USD')
.then(response => response.json())
.then(data => {
const currency = document.querySelector('#currency').value.toUpperCase();
const rate = data.conversion_rates[currency];
if (rate !==undefined){
document.querySelector('#res').innerHTML = `1 USD is equal to ${rate.toFixed(0)} ${currency}`
} else {
document.querySelector('#res').innerHTML = 'Invalid Currency';
}




})
.catch(error => {
console.log('Error', error);
});

return false;
}

});

</script>
</head>

<body>
<form>
<input id="currency" placeholder="Currency" type="text" >
<input type="submit" value="Convert">
</form>
<div id="result">
<hr>
<h1 id="res">

</h1>
<hr>
Note : Input the Currency Code e.g for Euro input 'EUR'
<br>
Note : Base currency = USD
<br>
<br>
<br>
Developed by Dave Eke - [email protected]


</div>
</body>
</html>

0 comments on commit 33a5b70

Please sign in to comment.