Skip to main content
blog title image

4 minute read - Linkedin Essays JavaScript

You can improve your JavaScript skills and have fun at the same time

Sep 28, 2016

I’ve slowly been improving my JavaScript skills. But in a slightly unconventional way…

Learning to code in the dim and distant past

Back when I was growing up, I had a ZX-Spectrum, and a lot of the games were written in BASIC. So having, loaded the game into the computer we were able to ‘break’ and stop the running application to view its code. We could also change the code, so we learned to program by hacking the games we had bought and loaded into our computer.

This was a normal process and encouraged by having:

  • cheat codes and pokes listed in magazines encouraged us to poke around with the games
  • type in applications in the same magazines - invariably these either had a typo in the listing, or we made a typo entering the code, so we had to learn to debug and amend the code

You wouldn’t learn how to write a complete application like this, but you certainly built an understanding of the language, and it was fun.

As games and computers grew more sophisticated, we had to learn how to use monitors and debuggers and disassemblers, and it wasn’t as easy, and it wasn’t as fun.

Then consoles stopped us messing with the games at all.

Learning to code by hacking JavaScript games

But now, with more and more games being written in JavaScript, we have the same opportunity available.

All the code is sitting there in the browser:

  • open the dev tools
  • look at the sources tab
  • pretty print the source

We can read the code, and learn from it.

Since the application is running when you are doing this, we can use the JavaScript console to:

  • change variables
  • patch code by creating new functions and assigning them to the running objects
  • create ‘bots’ that run alongside the game code using setInterval

This is fun, and educational.

Learning to code by playing games

There are games out there that encourage you to code to complete the game:

Both of the above are fun to play.

But I prefer the ‘hacking JavaScript games’ approach.

Why ‘hacking’ is better for testers

When you play the games designed to help you learn to code, you:

  • receive hints and objectives
  • work in a very controlled environment
  • find it hard to do anything ‘really’ bad
  • don’t really learn the underlying application
  • concentrate on snippets with no context

When ‘hacking’ you have to:

  • read the code
  • find entry points to start experimenting
  • come up with ideas to explore and try out
  • figure out what you have done wrong
  • write your own tools e.g. recursively scan the memory to find a variable, scan the top level instantiated objects but ignore those that are standard with the browser
  • learn a lot more

I personally like the challenge that hacking a game offers.

And part of the challenge is to make your ‘hack’ operate as part of the game rather than just be a ‘cheat’.

For example:

  • with Z-Type I created a new ‘onslaught’ mode where the game difficulty increased every 5 seconds and so levels never completed, they just rolled into each other with no letup - making the game feel very different
  • with “World’s Biggest Pacman” I created a new game mode where your Pacman speed randomly changed every second - sometimes you moved faster, sometimes slower, and sometimes you stopped. This created a fun variant on the game.

Incorporate this into your testing

When you learn to do this, it becomes natural to incorporate these as skills into your testing.

  • Automatically create data
  • Manipulate the application state
  • Extract information from the system
  • etc.

Learning how to do this has added new options when I test web applications.

And it was fun.

To learn more

I wrote some blog posts on this topic:

Try your hand at games to teach you coding:

Hack some games:

http://worldsbiggestpacman.com/ http://zty.pe/

Take a course: