On being stuck

If you're not stuck, you're not programming.

Expect to be stuck.

When you get unstuck is when you learn the most.

(This slide is from the very first slide deck I showed you on the first day of the year.)

How not to get unstuck

Get the answer from someone else.

This is like having someone else lift weights for you in the gym.

You’ve missed the chance to build your mental muscles and are no stronger than when you started.

How to get unstuck, usefully

Step 1: Get as clear as you can on what exactly you are trying to do.

Step 2a: If you think you know how to do it, try.

Step 2b: If you have no idea know how to do that thing, break it into smaller pieces and go back to Step 1.

When you try stuff and it works

Great! Now go back to the bigger thing and see if you can do another part.

When you try stuff and it doesn’t work

Figure out why not.

Is there an error message? Can you figure out what it means?

Did something happen but not what you wanted? How can you change your code so something different happens.

Did nothing seem to happen? Can you try to do something simpler so you’ll be sure it happens?

Breaking it down

Actual goal: “When I click in a box I want to put an X or an O, depending on whose turn it is, in that box.

“When I click in a box I want to put an X in that box.”

“I want to put an X in a box.”

“I want to put an X somewhere on the page.”

“When I click in a box I want something to happen.”

Once you’ve broken it down

Have you written code before that does basically the same small thing you are trying to do?

If you have but you don’t remember it exactly, can you find it and copy it?

Note, you’ll then have to adapt it to the new circumstances.

A few tricks

Make something show up on the web page.

Use console.log to make sure things are happening or to see the value of variables.

Always keep the console open in the inspector so you will see if you have errors in your script that prevent it from running.