Hi
<h2 id="h2">click me </h2>
<p class="shirt"> </p>
var test = "reddish"; // Global scope ??
var hm;
console.log(test); //value is 'reddish' here
function red(test) // passing 'reddish'
{
var reddy= "blue"; // local scope - using this another var produces blue shirt
console.log(test); // i dont understand how it is 0 here
hm =test + "shirt";
return hm;
}
$(function(){
$('#h2').click(function(){
$('.shirt').html(red);
});
});
I am trying to print "Red shirt " inside
.
But the value of test becomes '0' inside function red();
Also when i declare a variable inside function red() (eg reddy.. ) it is correctly used as blue.
So i would like to know what mistake i am doing and how can i pass test into the function as is.
Thanks