0

Im having a problem with my react app, where im unable to show the same icon from skycons twice. I found this post with the same issue. However - when I copy the solution I get an error bundle.js:130 Uncaught ReferenceError: e is not defined

For reference this is my code

componentDidMount() {
 this.serverRequest = $.get(this.props.source, function (result) {
  this.setState({
    forecast: result.currently,
    daily: result.daily.data
  });
  var icons = new Skycons({
      "color": "#666"
    }),
    list = [
      "clear-day", "clear-night", "partly-cloudy-day",
      "partly-cloudy-night", "cloudy", "rain", "sleet", "snow", "wind",
      "fog"
    ],
    i;

  for (i = list.length; i--;) {
    var weatherType = list[i],
      elements = document.getElementsByClassName(weatherType);
    for (e = elements.length; e--;) {
      icons.set(elements[e], weatherType);
    }
  }

  icons.play();
 }.bind(this));
}

I've tried to declare e different places in the code, but it didn't work for me, even though the code is copy/pasted

And obviously the error is somewhere here for (e = elements.length; e--;) {

Community
  • 1
  • 1
frisk0
  • 259
  • 1
  • 6
  • 15

1 Answers1

0

I think you want this:

  for (i = list.length; i--;) {
    var weatherType = list[i],
      elements = document.getElementsByClassName(weatherType);
    for (var e = elements.length; e > 0; e--) {
      icons.set(elements[e], weatherType);
    }
  }
ShaneDaugherty
  • 427
  • 4
  • 7
  • This just returns a console error from the skycons.js script – frisk0 Oct 24 '16 at 17:28
  • The biggest difference I can see here is that you should have a delimiter. e > 0 which should prevent from running for eternity. But should also include i > 0. – Urasquirrel Oct 25 '16 at 00:37