javascript - JS not working correctly -


i have html page, 2 buttons: 1 onclick="reshuffle('c') on it, , other onclick="reshuffle('bw'). then, have javascript:

function reshuffle(set) {     if (set = "bw") {         console.log("shuffling b&w pictures...");         var blackandwhite = shuffle(resize([], 20)); // second arg # of images in folder         go(blackandwhite, "bw");     }     if (set = "c") {         console.log("shuffling color pictures...");         var color = shuffle(resize([],  0)); // second arg # of images in folder         go(color, "c");     }     function resize(array, size) {         (i = 1; < size + 1; i++){array.push(i)}         return array;     }     function shuffle(array) {         var = array.length,             j = 0,             temp;         while (i--) {             j = math.floor(math.random() * (i+1));             temp = array[i];             array[i] = array[j];             array[j] = temp;         }         console.log("array shuffled: " + string(array));         console.log("length: " + array.length);         return array;     }     function go(listname, shortname) {         (i = 1; < 16; i++) { // (i = 1; < # of <img>; i++)             var index = listname[i - 1];             console.log( + ": " + index + " = " + listname[i - 1]);             document.getelementbyid("img" + + shortname).src="imgs/" + shortname + "/" + index + ".jpg";         }     } }  reshuffle("bw"); reshuffle("c"); 

the issue is, no matter -- reshuffle("bw") or reshuffle("c"), button or console, "reshuffles" both.

what js takes 15 random images directory , assigns them 15 <img> tags. both black , white image section, hence bw, , color section, hence c.

as commenter said need have

if (set == 'bw') {} 

and

if (set == 'c') {} 

otherwise assignment returns true , if test executed


Comments

Popular posts from this blog

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -