Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

exchange rates api

$(document).ready(function () {
  // some variables

  var baseCurrency = 'USD';

  var baseNumber = 1;

  var targetCurrency = 'INR';

  var targetNumber;

  var url;

  currencyConverter(baseCurrency, baseNumber,targetCurrency,targetNumber)

  // get base currency value

  $("#base").change(function () {
    // base currency

    baseCurrency = $(this).children("option:selected").val();

    // call currencyConverter function

    currencyConverter(baseCurrency,baseNumber,targetCurrency,targetNumber)


  });

  // get base currency number

  $("#baseNumber").change(function(){

    // base number

    baseNumber = $(this).val()

    // call currencyConverter function

    currencyConverter(baseCurrency,baseNumber,targetCurrency,targetNumber)

  })

  // get target currency value

  $("#target").change(function () {
    // target currency

    targetCurrency = $(this).children("option:selected").val();

    // call currencyConverter function

    currencyConverter(baseCurrency,baseNumber,targetCurrency,targetNumber)

  });

  // get target currency number

  $("#targetNumber").change(function(){

    // target number

    targetNumber = $(this).val()

    // call currencyConverter function

    currencyConverter2(baseCurrency,baseNumber,targetCurrency,targetNumber)

  })


  // function to convert BaseCurrency to TargetCurrency

  function currencyConverter(baseCurrency, baseNumber,targetCurrency,targetNumber)
  {
      // api url

      url = "https://api.exchangeratesapi.io/latest?symbols="+targetCurrency+"&base="+baseCurrency

      // make a get request to api

    

      $.get(url,function(data){
          console.log(data.rates)

          for (let [key, value] of Object.entries(data.rates)) {
            
            var result = value * baseNumber

           $("#targetNumber").val(result)

          }
          console.log(`data.rates.${targetCurrency}`)
      })
  }

  function currencyConverter2(baseCurrency, baseNumber,targetCurrency,targetNumber)
  {
      // api url

      url = "https://api.exchangeratesapi.io/latest?symbols="+baseCurrency+"&base="+targetCurrency

      // make a get request to api

      $.get(url,function(data){
          console.log(data.rates)

          for (let [key, value] of Object.entries(data.rates)) {

            console.log(value)
            
            var result = value * targetNumber

           $("#baseNumber").val(result)

          }
          console.log(`data.rates.${targetCurrency}`)
      })
  }


});Copy
Comment

PREVIOUS NEXT
Code Example
Java :: android how to get month on world programmatically 
Java :: how can you make a void method that transfer money from one account to the other on java 
Java :: Java create an object of the non-static class Reptile 
Java :: java resultset to object 
Java :: Using Looping Construct to Copy Arrays Java 
Java :: java GLIBC 2 34 missing 
Java :: change button background drawable in code Close 
Java :: java map get if contains else 0 
Java :: blast multiple protein files 
Java :: java main setup 
Java :: what is collection fromework 
Java :: how to make easy animations in canva 
Java :: read only jtextfield 
Java :: java application security best practices 
Java :: java exe ausführen 
Java :: Zooming an Image using OpenCV in Java 
Java :: processing java screen wrap 
Java :: for-each Loop Sytnax JAVA 
Java :: android studio how to move a picture canvas 
Java :: java code to get all leaf nodes of a xml file 
Java :: how to find all apps on android device using java 
Java :: how to add 0 in left padding using regular expression java 
Java :: android prevent screen from turning off programmatically 
Java :: diiferent ways to run spring boot 
Java :: how to split each string of a line 
Java :: get time zone from co-ordinates java 
Java :: Write a java program to merge three singly linked list elements 
Java :: convert from java to kotlin online 
Java :: num* num 
Java :: last resultset method 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =