0

I cant pass a test because canoo does not support global variables in extrenal js-file.

index.html:

<html>
   <head>
      <script src="index.js"></script>
   </head>
   <body>
      <button onclick="alert(a+1);">asldkf</button>

   </body>
</html>

index.js

var a=1;

CanooWebtest throws:

JavaScript error loading page 
http://localhost:8080/index.html: 
  ReferenceError: "a" is not defined. (JavaScriptStringJob#1)

Any suggesstions?

Grim
  • 1,938
  • 10
  • 56
  • 123
  • I wouldn't try executing that script until the document is loaded and ready. – jbabey Jan 30 '13 at 13:39
  • You should NOT use empty tag notation with script elements since [not all browsers handle it properly](http://stackoverflow.com/questions/69913/why-dont-self-closing-script-tags-work). – epascarello Jan 30 '13 at 13:50
  • @jbabey, ok, iv edited my question, the error comes anyway. – Grim Jan 30 '13 at 13:51
  • @epascarello, ok, iv edited my question, the error comes anyway. – Grim Jan 30 '13 at 13:52

1 Answers1

0

You could always trick it and add it to one of the global objects - Window, Document... Not a good solution but should work.

<script>
    window.a = 1;
</script>
Martin
  • 461
  • 2
  • 9