rename - Creating a Javascript Variable with the Length of an Array -
in function need create new variable called "dorfx". x length of array variable go in. instance, produce variable called "dorf5" parameters specified in function "makeadorf". however, doesn't want work because name of variable isn't identified.
from can tell, either need rename variable somehow or figure out how make work.
this has simple answer, i'm pretty new programming , grateful if help. thanks.
function guildrecruit(){ var price = math.floor((math.random()*100)+1) + (dorves.length*50); var recruit = prompt("hello there friend. recruit adventurer?"); if(recruit == "yes"){ var dorf(dorves.length) = new makeadorf("testificate","123"); dorf(dorves.length).push(dorf(dorves.length)); }else{ confirm("thank visiting dragon slayer guild."); } }
i think little confused on how set code. guessing wrote, looks want function either:
- creates new dorf / adventurer , remembers it
- does nothing other write message
to want create array outside function. i'll refer array "adventurers". if condition make new dorf true, push new dorf "adventurers" array. (note: removed code uses dorves):
var adventurers = []; // new array(); same thing, read jan dvorak's comment function guildrecruit() { var price = math.floor((math.random()*100)+1); var recruit = prompt("hello there friend. recruit adventurer?"); if (recruit == "yes") adventurers.push(new makeadorf("testificate","123")); else confirm("thank visiting dragon slayer guild."); }
edit: can't think of case creating variables numbers useful. not possible so. point of array use logic similar dorves referenced adventurers[0]
instead of adventurers(somefunction)
.
Comments
Post a Comment