Codecademy CodeYear Lesson 10 – Arrays and Rock, Paper, Scissors

Ah, arrays. It was bad enough with one dimension, but two dimensions? Three dimensions? This week’s lesson, which for the record I found incredibly tough but rewarding, again carried on the theme of taking a concept and running with it rather than throwing random exercises together (and dedicating the first section to revising old topics was very useful, please keep that up Codecademy!) It quickly developed into quite complex looping exercises, that generally had enough explanation to set you on the correct path without giving you the answers on a plate.

However, once the lesson started talking about associative arrays, I was lost – I definitely get the impression that these are important (in that they differ from indexed arrays because of the key/value pairing distinction) but I don’t necessarily see why.  The associate card array with rank and suit keys just didn’t gel with me – and I ended up Googling to find out more.  Try this excellent blog post if you too are struggling with the concept!

As usual, I fought through, with some liberal sprinkling of hints, and eventually managed to write the code to deal out two hands of poker:

On the bright side, the Rock, Paper, Scissors game was generally much more straightforward, if a little bit typing heavy! The !=== null option for the prompt was an interesting nugget, as was toLowerCase(), but there was nothing too difficult apart from making sure all the spaces appeared in the console.log statement as well as the programmed variables (I seem to draw blanks when it comes to “” in console.log statement!)

Final game code pasted below:

I hear the next week’s back to recursion again.  Is it or me, or do we seem to just keep going back to recursion?  Oh, wait…


Tagged , , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: