This is my current code:
This is the output its giving me:
i need to remove the \n at the end with an if statement for the output +='\n';[/CODE]
JavaScript:
function createGrid(height, width) {
var output = '';
for (var i = 0; i < height; i++) {
for (var j = 0; j < width; j++) {
if ((i + j) % 2 === 0) {
output += " ";
} else {
output += "#";
}
}
output += '\n';
}
return output;
}
console.log(createGrid(8, 8));
console.log(createGrid(3, 3) === " # \n# #\n # ");
console.log(createGrid(4, 3) === " # \n# #\n # \n# #");
This is the output its giving me:
# # # #\n# # # # \n # # # #\n# # # # \n # # # #\n# # # # \n # # # #\n# # # # \n
i need to remove the \n at the end with an if statement for the output +='\n';[/CODE]
Last edited by a moderator: