Reputation: 3
Very new to JS here. When I write PHP I have no problem assigning variables inside a function, but inside a JavaScript function it doesn't work. Why?
example:
function hello() {
var animal = 'Dog';
document.write(animal);
}
Upvotes: 0
Views: 161
Reputation: 78981
put this snippet inside your function to check if your function is being called
alert('snippet');
If a message box appears, your code should work, but if it does not then the function is not being executed, post some html coding also.
Upvotes: 1
Reputation: 129403
Are you calling the hello()
function anywhere? If not, you will not execute the contents of the function and thus, no write
will happen.
Upvotes: 7