javascript - How to alternate values in an array? -


i new javascript, , struggling 1 question class. easy, stuck @ moment.

anyway, here problem:

i have create table of alternating characters of x , o based on user-specified number of rows , columns. instance, if user wanted 3 rows , 3 columns, have this:

xox oxo xox 

i lost on how can create alternating value in array. have far (below), logic of wrong. if can give me advice great! have been looking @ problem days, can’t seem piece together.

// = user input # of columns // b = user input # of rows  function firsttest(a,b) {   var firstarray = [];   var total = [];   (i = 0; < a; i+=1) {             firstarray.push("xo");   }   (i=0; i<b; i+=1){     total.push(firstarray);   }   return(total); } 

you need check if sum of value of row , value of column odd or even:

function firsttest(a,b) {     table = [];     ( x = 1 ; x <= ; x++ ) {         row = [];         ( y = 1 ; y <= b ; y++ ) {             if (((x+y) % 2) == 0) {                 row.push('x');             } else {                 row.push('o');             }         }         table.push(row);     }     return table; } 

Comments

Popular posts from this blog

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

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

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