Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Error with variables in JavaScript

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #167567
    Chris Lowles
    Participant

    Could someone look into this, the function isn’t returning the way i need it to be.

    #167568
    Alen
    Participant

    What are we looking at? What are you trying to do?

    #167570
    Chromawoods
    Participant

    Uncaught ReferenceError: $ is not defined

    You have not included jQuery?

    #167571
    Alen
    Participant

    wikiaPageType != "forum" this means is NOT equal to, which is denoted by the !=.

    #167572
    Alen
    Participant
    
    var wikiaPageType = "forum";
    
    (function(){
      
      if ( wikiaPageType === "forum" ) {
        console.log("yes, it's forum");
      }
      
    })();
    
    #167611
    __
    Participant

    the function isn’t returning the way i need it to be.

    The function doesn’t return a value at all. It logs a message and then returns nothing.


    @Alen
    ’s comment probably answered your specific question, but beyond that, you should be passing your variable into the function deliberately, rather than falling back onto the global scope.

    var wikiaPageType = "forum";
    
    (function( wpt ){
        if( wpt === "forum" ){
            console.log( "you're in the forum" );
        }
    })( wikiaPageType );
    
Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.