Skip to content
Advertisement

Printing a snake pattern using an array

I’m having trouble with an assignment where we are required to print out this array:

JavaScript

My code is somewhat correct but it is not printing 10 and 19 where it should be.

My output:

JavaScript

My code:

JavaScript

Can anyone detect what is causing the error? Any help would be appreciated.

Advertisement

Answer

This will generate the “snaking” pattern you described.

It could be simplified with ternary but this makes it more readable I think

It would be interesting to find a more clever way about it though, if anyone finds a better way pls comment

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement