- This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
Viewing 6 posts - 1 through 6 (of 6 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › Error with variables in JavaScript
Could someone look into this, the function isn’t returning the way i need it to be.
What are we looking at? What are you trying to do?
Uncaught ReferenceError: $ is not defined
You have not included jQuery?
wikiaPageType != "forum"
this means is NOT equal to, which is denoted by the !=
.
var wikiaPageType = "forum";
(function(){
if ( wikiaPageType === "forum" ) {
console.log("yes, it's forum");
}
})();
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 );