Search the Community
Showing results for tags 'condition'.
-
Hello, I am still rather new to JavaScript. I am working on making a study tool for school. Below I have a sample of my code. I would like for a case to included in the array WordList only if a condition is true. I have check-boxes for each case. What I have currently is a poor workaround where if for example case 1's box is not checked it will shuffle again and then run the function again. Instead, I would like to make it so that if case 1's box is not checked it won't be included in the array at all, if that's possible. I'm sorry I can't explain this very well. Thanks in advance for any input. Array.prototype.randomize = function(){ var i = this.length, j, temp; while ( --i ) { j = Math.floor( Math.random() * (i - 1) ); temp = this[i]; this[i] = this[j]; this[j] = temp; }}var WordList = [0,1];WordList.randomize();function Word() {var WordL = WordList [0];switch (WordL) { case 0: if(document.getElementById('micro').checked) { WordL = MicroList.randomize(); Micro();} else {WordList.randomize(); Word();} break; case 1: if(document.getElementById('immuno').checked) { WordL = ImmunoList.randomize(); Immuno();} else {WordList.randomize(); Word();}}}
- 8 replies
-
- javascript
- switch
-
(and 3 more)
Tagged with: