javascript - Variable Implicitly Declared and Prototypes -


trying keep short. using phpstorm on code , got few errors.

it says function naming locations has "variable implicitly declared"

function towngate10() {     updatedisplay(locations[10].description);     if (!gate10) {         score = score+5;         gate10 = true;     }     playerlocation = 10;     displayscore();     document.getelementbyid("gonorth").disabled=true;     document.getelementbyid("gosouth").disabled=false;     document.getelementbyid("goeast").disabled=true;     document.getelementbyid("gowest").disabled=true; } 

also, want make sure went prototypes correctly sample

global arrays:

var locations = [10]; locations[0] = new location(0,"intersection","this awoke."); locations[1] = new location(1,"cornfield","the cornfields expand miles."); locations[2] = new location(2,"lake","a large lake formed river flowing east.", new item(1,"fish","an old rotting fish.")); locations[3] = new location(3,"outside cave","entrance dark cave."); 

location function:

function location(id, name, description, item) {     this.id = id;     this.name = name;     this.description = description;     this.item = item;     this.tostring = function() {         return "location: " + this.name + " - " + this.description;      } } 

regarding variables being implicitly declared:

if (!gate10) {     score = score+5;     gate10 = true; } 

and

playerlocation = 10; 

score,gate , playerlocation being created 'global' variables. phpstorm alert this. unless intended globally accessible, declare variables var instead. make variables local scope in it's created:

if (!gate10) {     var score = score+5;     var gate10 = true; } 

and

var playerlocation = 10; 

i suggest read more variable scoping. global variables can leave gaps in security if aren't handled.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -