It’s me vs. Rock, Paper, Scissors. Let’s code. (Day 7)

Rabee AmanRabee Aman
3 min read

After a short break (weekends do get in the way), I’m back and ready to get straight back to coding!

On day 6, I built my first actually useful simple website. I've halted it for now since I've got a lot to learn.

Today began with something I always groan at: errors.

Let's Talk About Errors

Let's face it, most beginners including me aren't quite happy when we see a looming red text appear on the console. It's a sign that something's gone wrong. But TOP gave me a new perspective: errors are your friends.

They’re not just annoying messages. They’re like your code’s way of telling you what went wrong and where. Think of errors not as a chore, but as a puzzle to debug.

I made a small list of notes to keep in mind:

  1. Errors are helpful, not harmful.

  2. You don’t need to memorize every error message. Just Google them when you run into one. It'll steadily and surely catch on.

  3. Use console.log() like your life depends on it. It’s a built-in debugging tool that lets you peek into what your code is doing (or not doing.)

I used one of the practice exercises from TOP to get hands-on with debugging. It was satisfying to pop error messages out of existence, one by one.

I was then faced by a new challenge: Rock, Paper, Scissors.

Rock, Paper, Scissors, Code

TOP asked me to build Rock, Paper, Scissors from scratch. At first, I was confused. Where do I even begin with something like this?

Then I remembered last session: use the art of problem solving. Break the problem down.

I needed a step-by-step plan. This is what I jotted down:

  1. Write a function that randomly picks between rock, paper, or scissors.

  2. Set up a way for me to input my choice into the game.

  3. Compare both choices and figure out who wins that round.

  4. Keep track of the score (first to reach 5 points wins.)

  5. Add a way to restart the game after it's over.

Breaking it down helped massively. The solution went from a blank slate to recipe for success.

By the end of today's session, I was able to cross step 2. I made two functions: one that put my choice in and another that spits out the computer's choice. Here are the functions I made:

Simple, but effective. Now, all I need to do is find a way to connect them into a proper game. I have to admit, JavaScript's getting a lot more fun since I'm able to do actual projects. The 3 hour session was piece of cake.

Tomorrow, I'll hopefully complete the game and find time to learn a bit more!

0
Subscribe to my newsletter

Read articles from Rabee Aman directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rabee Aman
Rabee Aman