9/7 11:14:09p Node 1 !javascript c:\sbbs\xtrn\solar\alco-solar.js line 275: typeError: sfi.trim is not a function
So, my first question is, is the trim() function valid in JavaScript 1.8.5? I'm guessing it is because it's been working in
What I find interesting is that the error flagged on a trim() on line 275, but was OK with the trim() on line 270: timestamp.trim().
So, my first question is, is the trim() function valid in JavaScript
1.8.5? I'm guessing it is because it's been working in
Yes, it's a valid method on a String object.
What I find interesting is that the error flagged on a trim() on line
275, but was OK with the trim() on line 270: timestamp.trim().
In this case 'timestamp' is really just another String, since you're just grabbing the text from the feed and not turning it into a Number or Date object, so that makes sense.
My best guess is that the 'solarflux' value was absent when this person fetched the feed, or that they failed to fetch the feed altogether. On line 80, if 'solardata.solarflux' is undefined, 'sfi' gets set to 0, a Number, which does not have the '.trim()' method. Wrap that 0 in quotes on line 80 and this particular problem should go away.
Also, if you wanted to, you could also shorten things a bit by doing something like:
var sfi = solardata.solarflux || '0';
var sfi_int = parseInt(sfi);
var ai = solardata.aindex || 'No Data';
// etc.
That would be like a shorter version of:
var sfi = (typeof solardata.solarflux == 'undefined' ? '0' : solardata.solarflux);
Which is a shorter version of:
var sfi = solardata.solarflux;
if (sfi == undefined) {
var sfi = '0';
}
Sysop: | Tandy |
---|---|
Location: | New York, USA |
Users: | 15 |
Nodes: | 13 (0 / 13) |
Uptime: | 04:30:25 |
Calls: | 335 |
Messages: | 112,923 |