Skip to content

Instantly share code, notes, and snippets.

@hakimzulkufli
Last active August 18, 2018 10:51
Show Gist options
  • Save hakimzulkufli/791d82ffa124ba91ffe4305064b81425 to your computer and use it in GitHub Desktop.
Save hakimzulkufli/791d82ffa124ba91ffe4305064b81425 to your computer and use it in GitHub Desktop.
Print chess board. Alternate solution. Demo: https://codepen.io/anon/pen/qyezvX
<pre id="output"></pre>
<script>
var n = prompt("Enter value of N", 5), c = 1, str = "";
for(i = 1; i<=n; i++) {
if(i % 2 === 0) c = 2;
else c = 1;
for(j = 1; j<=n; j++) {
if(c % 2 !== 0) str += "#";
else str += "&nbsp;"
c += 1;
}
str += "<br />";
}
document.getElementById("output").innerHTML = str;
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment