1)
function chessboard(size){
var i=0, _size=size*size, output='';
for(;i<_size; i++){
// add a new line if we need two
if (i % size === 0)
output= output +'\n' ;
// determine whether we need a hash or a space
output = output + (i%2 ? '#': ' ');
}
// append a new line at the end for proper formatting.
return output + '\n'
}
2) As you said the first line isn't aligned correctly because of the quote, so you need to add a new line character to the beginning.
in the second set what you're doing is prepending to the string essentially building it backwards. after each execution instead of adding the # or ' ' at the end of the string you're putting it at the beginning. At the end you prepend the newline character to the beginning of the string which makes it start on a new line.