Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script Processor in Javascript for currency conversion
addLibrary("http");
var output1;
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "http://demo7684243.mockable.io/curr_rates", false);// Here goes your web service URL
xmlHttp.send();
var responseData = xmlHttp.responseText;
var dataJSON = JSON.parse(responseData);
var baseCurr = dataJSON["base"];
var baseCurrRate = dataJSON["rates"];
var convertFrom = input1[1];
var convertTo = input1[2];
var convertFromRate = dataJSON["rates"][convertFrom];
var convertToRate = dataJSON["rates"][convertTo];
if (convertFrom == convertTo) {
convertToRate = 1;
convertFromRate = 1;
}
if (convertTo == baseCurr) {
convertToRate = 1;
}
if (convertFrom == baseCurr) {
convertFromRate = 1;
}
var convertedVal = (input1[0] * convertToRate) / convertFromRate;
output1 = convertedVal.toFixed(2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.