javascript - MyFunction() Uncaught Reference error -


error: uncaught referenceerror: myfunction not defined

this .js file isn't working or calling on html

function = myfunction()  {     var ret = "";     (var = 15; < 26; i++)      {         ret += + "  " + i*2 + "  " + i*3 + "\n";         }     alert(ret); } 

this html code:

<!doctype html> <html>  <head> <script type="text/javascript" src="test1.js"></script>  </head>  <body>  <h1> exercise 4 - lab 4  </h1>  <h2> exercise 2.1 </h2>  <button type="button" onclick= "myfunction() "> press me </button>  </body> </html> 

error: uncaught referenceerror: myfunction not defined

here go:

var myfunction = function () {     var ret = "";     (var = 15; < 26; i++)     {         ret += + "  " + i*2 + "  " + i*3 + "\n";     }     alert(ret); }; 

function = varname () {} syntax error. can this: function varname () {} without equals sign, or can way did it.

after little bit of healthy admonishment of our fellow posters, should point out there difference between these 2 ways write function. quote robg: "there no practical difference between function foo(){} , var foo = function(){}; other when function created , first called functiondeclaration , second functionexpression." function declaration loaded before code executed, can can call anywhere (before or after function's location in file). however, again in terms of actual location in file, if call function expression before location in file, error thrown. (you can around declaring variable later assigned function expression @ beginning of file.)


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -