Contact me at kwokster10@hotmail.com
I love furry animals but dogs trump them all. My new background from exploring Bored Panda.
//So this is from the last exercise of the fundamentals.
//I think I did it right but have a feeling that using .map function would have made my code cleaner.
//Any thoughts?
function clearBoard() {
for (var i=0; i<checkerboard.length; i += 1) {
var h=0;
while (h<checkerboard.length) {
checkerboard[i][h] = null;
h+=1;
}
}
}
function setUpRed() {
for (var i=0; i<3; i += 1) {
var h=0;
if (i%2===0) {
for (h=0; h<checkerboard.length; h+=2)
checkerboard[i][h] ='R';
} else {
for (h=1; h<checkerboard.length; h+=2)
checkerboard[i][h] ='R';
}
}
}
function setUpBlack() {
for (var i=5; i<checkerboard.length; i += 1) {
var h=0;
if (i%2===0) {
for (h=0; h<checkerboard.length; h+=2)
checkerboard[i][h] ='B';
} else {
for (h=1; h<checkerboard.length; h+=2)
checkerboard[i][h] ='B';
}
}
}
var pieces = {
"red" : [],
"black" : []
};
function piecesRed() {
for (var i=0; i<checkerboard.length; i+=1) {
for (var h=0; h<checkerboard.length; h+=1) {
if (checkerboard[i][h] ==='R') {
pieces["red"].push([i,h]);
}
}
}
}
function piecesBlack() {
for (var i=0; i<checkerboard.length; i+=1) {
for (var h=0; h<checkerboard.length; h+=1) {
if (checkerboard[i][h] ==='B') {
pieces["black"].push([i,h]);
}
}
}
}