私は画像の配列を持っています
var prizeImage;
//this is a dynamic amount
var result = 55;
//the length of this array will change. Images will be added/removed
var prizeImageArray = ['image1.png','image2.png','image3.png','image4.png']
//I want to avoid having to type each of these if statements.
if(result < 25){
prizeImage = prizeImageArray[0];
}
if(result > 26 && result < 50){
prizeImage = prizeImageArray[1];
}
if (result...)//and so on
上記はひどいコードです。
賞品の画像配列のサイズを変更し、各ifステートメントの入力を回避できるメソッドが必要です。
これが理にかなっていることを願っていますが、そうではないと感じています。