这个问题应该很简单,但是如何替换数组或定义它,然后根据用户选择给出值。下面带有if语句的代码是我在一个或两个数组中需要的一些选择。
例如
if(choice=="easy")
{
var sorted:Array = new Array("Beau","Dad","Jesus","Mary","Mom");
}
if(choice=="hard")
{
var sorted:Array = new Array("Beau","Dad","Jesus","Mary","Mom","Jordyn","Presley","Daddy","Mommy","Grandma","Grandpa","Nana","Gepa");
}
但这不适用于上述情况。 谢谢。
答案 0 :(得分:1)
在条件之外声明变量(我也将if/if
更改为if/elseif
,因为choice
不能 easy
和{ {1}}同时):
hard
答案 1 :(得分:1)
作为h2oooooo'答案的附加选项,你可以使用类似的东西:
var sorted:Array = {
"easy":["Beau","Dad","Jesus","Mary","Mom"],
"medium":["Jordyn","Presley","Jesus","Mary","Nana"],
"hard":["Beau","Dad","Jesus","Mary","Mom","Jordyn","Presley",
"Daddy","Mommy","Grandma","Grandpa","Nana","Gepa"]
}[choice];
trace(sorted.constructor); // [class Array]