First off, here's my code:
var variable1 = 10;
function f1 (){
alert(variable1);
}
//When button is pressed, call function
$("#button").click(f1);
Why can I not access variable1 inside the function? Many thanks and a Happy Christmas.
Modified question
$(document).ready(function() {
var how_many_words = 3;
alert(how_many_words); //This happens
$("input").keypress(check_word);
function check_word(){
alert('hello'); //This happens
alert(how_many_words); //This doesn't
}
});