Hello ,
I am new to javascript and I have the following code in c :
#include <stdio.h>
#include <stdlib.h>
int main()
{
int height = 8, width = 8;
for ( int i = 0; i < height; i++ )
{
for ( int j = 0; j < width; j++ )
{
if (i % 2 == 0)
{
if ( j % 2 == 0 ) printf("#");
else printf(" ");
}
else
{
if ( j % 2 == 0 ) printf(" ");
else printf("#");
}
}
printf("\n");
}
return 0;
}
which produces :
# # # #
# # # #
# # # #
# # # #
# # # #
# # # #
# # # #
# # # #
and I am trying in javascript:
var width = 8;
var height = 8;
for ( var i = 0; i < height; i++ )
{
for ( var j = 0; j < width; j++ )
{
if ( i % 2 === 0 )
{
if ( j % 2 === 0 )
console.log("#");
else console.log(" ");
}
else
{
if ( j % 2 === 0 )
console.log(" ");
else console.log("#");
}
}
console.log("\n");
}
which produces :
#
#
#
#
#
#
#
#
...
I can't figure why?
Is console.log the problem?
Thanks!