Global var not testable

79 Views Asked by At

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?

1

There are 1 best solutions below

3
On

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>