JSFiddle - React, Tailwind, and code Playground
by grant
HTML
<div>
snow d
</div><div id="snowd">
</div>
<p id="source"></p>
<p id="demo">x</p>
JavaScript
// get the date and time to set the realtime end for this year
// https://jsfiddle.net/pcr8xbt5/
Date.prototype.mytime = function() {
var mm = (this.getMonth() + 1).toString(); // getMonth() is zero-based
var dd = this.getDate().toString();
var hh = this.getHours().toString();
var mmm = this.getMinutes().toString();
// console.log(hh);
return [this.getFullYear(),
mm.length===2 ? '' : '0', mm,
dd.length===2 ? '' : '0', dd,
hh.length===2 ? '' : '0', hh,
mmm.length===2 ? '' : '0', mmm].join(''); // padding
};
var date = new Date();
var today = date.mytime();
console.log(today);
//mesowest json from url
//https://stackoverflow.com/questions/20148239/use-multiple-urls-with-getjson
var res = 'timeseries';
// var res = 'precip';
var stn = 'BOGI1';
var tkn = 'demoToken';
var timez = "local";
var timef = "%m-%d-%Y";
let timeLegend = "%m-%d";
var start = '201811010001'; // s start
var end = today; // calc today js
var type1 = 'daily';
var snowd = 'snow_depth';
var units = 'precip|in';
var pmode = 'intervals';
var intvl = 'day';
var precip = '1';
var op = 'json';
// 2017 - current result1
$.getJSON('https://api.mesowest.net/v2/stations/' + res + '?callback=?',
{
// specify the request parameters here
stid:stn,
token:tkn,
start:start,
end:end,
var:snowd,
units:units,
timeformat:timef,
timezone:timez,
precip:precip,
output:op,
//jsonformat: 2 /* for diagnostics */
} ,
function (snow)
{
console.log(snow);
let sn17 = snow.STATION[0].OBSERVATIONS.snow_depth_set_1[12];
console.log(sn17);
document.getElementById('snowd').innerHTML = sn17;
/*
* do something with your returned data
*/
}
);
document.getElementById("source").innerHTML = "https://stackoverflow.com/questions/20148239/use-multiple-urls-with-getjson";
var x = myFunction(4, 3);
document.getElementById("demo").innerHTML = x;
function myFunction(a, b) {
return a * b;
}