Getting stuck happens even to the most experienced programmers. And while we’d love to tell you there’s a magic button that'll solve all your coding problems, that's not always the case. The good news? There are a lot of ways to get unstuck. In this article we’ll share a few general practices that you can use the next time you're stuck on a coding problem.
7 tips for getting unstuck when programming
First things first: don't panic. You've got this. Errors are not something to fear or be discouraged by — they’re actually opportunities for learning! So take a deep breath to calm yourself down before attempting any of these strategies to get unstuck.
Staying calm is the first step to staying positive. Believe in yourself and your ability to solve problems. You can figure this out, and it’ll be much more enjoyable if you do so from a mindset of learning and growth.
Read the error
Take the time to read the error you received. Not reading the error in detail or not understanding the error are common mistakes that new learners make. By understanding the errors you receive and connecting the dots between each error message and the solution to the problem, you’ll gain valuable coding skills.
When you get an error message while doing an exercise in Codecademy, you'll discover valuable clues that will direct you to where you can debug your code. For instance, an error message might say: "Oops! The test returned an error. Maybe you have a syntax error or typo." Now you know what type of error you are on the lookout for.
Check your spelling
Some of the most common errors we have are related to spelling and syntax. This means that somewhere in our code we’ve either misspelled or mislabeled something. An example would be if you forgot to encase your string in a set of quotations. The code won’t be able to read your mind and will not equate string with “string” as you intended.
Other common syntax errors are:
- Incorrect use of brackets and curly braces
- Using the wrong number of equal signs
- Using different cases (i.e., “name” and “Name” are two independent variables)
You can avoid many of these errors by being consistent with your conventions. An example of this is to always capitalize the first letter of your variables — that way you won’t encounter errors for letter case.
Try to program using the styling standards for the language you are using. Style guides will help to reduce your error rate by making your code more readable, which makes it easier to spot your mistakes.
Verbalize the problem
Another helpful strategy to get unstuck involves speaking your problem aloud. Your problem could be a section of code you’re working on, a problem you’re solving for a client, or even a personal project. Make sure you know what the outcome is supposed to be.
By speaking things out loud (even if no one is actually around), you begin to solidify in your mind what you’re trying to accomplish. Then you can circle back to your code and figure out if it does indeed accomplish what you need it to do. If there’s a piece of your code that isn’t assisting you in reaching your goal, that’s probably where the error lies.
Break down the problem
If you are looking at your code as one large block, it can seem like a massive undertaking to hunt down one error. But if you break your code down into smaller blocks, each accomplishing a small task, it will be much easier to figure out where the error is located.
As we talked about before, if you take the time to read and understand the error message, you’ll know what type of error you’re looking for. You can also use the verbalizing tip to talk about what each block of code does and whether that particular error could be within each block of code.
If you’re still stuck, you may need to walk your code backward. This means you reverse each step in your code until you find the error. This tip is especially useful if your code was working just fine in earlier sections. Chances are the error is at the bottom, so you’ll find it quicker by working in reverse.
Even though we said there wasn’t a magic button to help you get unstuck, sometimes Google is a pretty close alternative. If you’re working outside the Codecademy platform, Google can help you to search for a solution to a particular issue you are having.
Be as specific as possible when you are using Google to get unstuck. You can copy-and-paste your error message directly into Google and then take a look at the search results that seem most applicable to your piece of code. If the results that are returned aren’t helpful, think about how you could reword your search to get closer to the solution.
Let’s look at an example. If you got the error “Assignment to constant variable” you could search for it exactly in Google. But if it didn’t give you the information you needed, you could add the language to your search, or even the specific Codecademy exercise name, in the following sequence of attempts:
- Assignment to constant variable
Tap into programming resources
If you’re working through Codecademy course material, we have additional resources to help you get unstuck. In each and every exercise, you'll find a "Get Unstuck" link in the lower right corner. Click on it to find related forum threads, concept reviews, or code solutions.
The Codecademy Forums are also a great place to start practicing the skill of asking questions. Be sure to include the following information in order to maximize the chances of getting unstuck:
- Your formatted code
- The error message you received
- Explain what you don’t understand
- Add any other relevant information
Before asking a question, take a look at the question-and-answer exchanges that are already on the forum. There's been a lot of discussion and questions from learners that have gone through the same material you're going through. You might find the answer to your question is already there! In addition to that, you might learn something new and unexpected just by reading through how other learners got unstuck.
If you're stuck working on a project, you can also leverage Walkthrough Videos. These videos will take you through how to complete the project step-by-step.
Once you progress through the exercises and get unstuck, consider answering some questions on the forum to help other learners. You can lend a helping hand and let others lean on you, just like you leaned on them in the past!