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 :: java console readline null pointer exception 
Java :: call c function from java 
Java :: android getdrawable before api 21 
Java :: data input stream using while loop 
Java :: Write a java program to print the ip address 
Java :: how to create a udp protocol for transfer a big quantity of files java 
Java :: The Unit Circle Codehs 
Java :: wrap text in jscrollpane 
Java :: How to pass ArrayList of Objects from one to another activity using Intent in android? 
Java :: interfaces in java 
Java :: android paint drawtext multiline 
Java :: x/=y is the same as x=x/y 
Java :: Sample TreeMap 
Java :: java fill two dimensional array stream 
Java :: 2 multiples 
Java :: jsp form upload image 
Java :: c# param.ExStyle equivalent in java 
Java :: java instanciar objeto File 
Java :: detecting battery charging android 
Java :: what does the continue keyword do in java 
Java :: how to add new nod in dynamic treeview using javascipt 
Java :: java 8 if else in one statement 
Java :: telegraf-agent-configuration 
Java :: This version of the Android Support plugin for IntelliJ IDEA (or Android Studio) cannot open this project, please retry with version 2020.3.1 or newer. 
Java :: android api 21 join list of strings 
Java :: are inner classes inherited 
Java :: how to make jframe full screen 
Java :: are classes in java public by default 
Java :: += operator casting in java 
Java :: Give the output of the following code: int a = 10; int b = 20; String s = Integer.toString(a); String t = Integer.toString(b); System.out.println((s+t)); 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =