Help with JS code

Asked

Viewed 25 times

0

I have that code:

        if(post.link[k].type == 'post miniatura'){
          var postMiniatura = post.link[k].href;
        } else {
          var postImage;
          try {
            postImage = post.media$image.url
          } catch (error) {
            s = post.content.$t;
            a = s.indexOf("<img");
            b = s.indexOf("src=\"", a);
            c = s.indexOf("\"", b + 5);
            d = s.substr(b + 5, c - b - 5);
            if ((a != -1) && (b != -1) && (c != -1) && (d != "")) {
              postImage = d
            }
          }
        }

What I tried to do was this: Case the post.link[k].type be "thumbnail post" it executes the code and to, ie, does not execute the rest that is after the else. Only what happens is that even post.link[k].type be true, it executes the code after Else as well. I wanted what this after Else to be executed only if post.link[k].type was not equal to "miniature post". What do I do? (I’m a beginner in JS)

1 answer

1


Very simple. Using your logic, you can put a return after var postMiniatura = post.link[k].href;. That way, you will quit the JS function and not run what there is after the else.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.