JSFiddle - React, Tailwind, and code Playground

by pramendra

HTML

<form id="currency">NPR
  <input name="NPR" class="npr" type="text" />
  <br />JPY
  <input name="JPY" class="jpy" type="text" />
</form>

JavaScript

$(document).ready(function () {
  // http://www.google.com/ig/calculator?hl=en&q=1JPY=?NPR
  // under the hood its invoking but since jsonp is not supported

  var url = "http://rate-exchange.appspot.com/currency?q=1&from=JPY&to=NPR";
  $.getJSON(url + "&callback=?", null, function (data) {

    var rates = {
      npr: data.rate,
      jpy: 2 - data.rate
    };

    $('#currency input').keyup(function (e) {

      var amt = $(this).val();
      if (!isNaN(amt)) {
        switch ($(this).attr('name')) {
          case 'JPY':
            $('#currency .npr').val(rates.jpy * amt);
            break;
          case 'NPR':
            $('#currency .jpy').val(rates.npr * amt);
            break;
        }
      }
      
    });
  });
});