Wednesday, August 26, 2015

 Here is my second attempt at making the chessboard.  I think this code is a little bit simpler and it has a prompt so it is a bit more user friendly than the previous version.

var givenNum = Number(prompt("give a number, make a chessboard!"));
for (var firstLine = "#";firstLine.length <=givenNum ; firstLine+="#")
{
   if (firstLine.length == givenNum)
     break;
  firstLine += " ";
   if (firstLine.length == givenNum)
     break;
}
for (var secLine = " ";secLine.length <=givenNum ; secLine+=" ")
{
   if (secLine.length == givenNum)
     break;
  secLine += "#";
     if (secLine.length == givenNum)
     break;
};

var counter = 1;
var theLine = firstLine
while (counter <=givenNum)
{
  theLine += "\n" + secLine;
  counter++;
  if (counter ==givenNum)
    break;
  theLine += "\n" + firstLine;
  counter++;
  if (counter == givenNum)
    break;
};
console.log(theLine);