# How to Start When you are Stuck

You are a camper just like me, you get to an exercise and you get stuck … just like anyone else. You have no idea how to start, you stare at your editor and you think you must have a problem, surely you are not developer material … well you’re wrong! Perhaps you are just like me? I’m a visual person, I like a drawing better than a text. Everytime the same problem put down in a schema makes more sense to me than if you gave me a text. So … what do I do when I have problems solving/understanding an exercise? I start to draw. After I have my drawing in place, if I need more to translate it to code, I can also write it in pseudocode. After that, transposing it to code should not be very hard.

# So what are these flowcharts (the drawings) and pseudocode?

During my first semester in college, we had a course about introduction to algorithms. This is where we first learned about this stuff. We learned that a good algorithm and good logical programing is developed using flowcharts and pseudocode.

A flowchart represents your program flow from top to bottom. Each command is represented on this. Depending on the nature of the command, there are different shapes you can use. A few of them that I mostly use (you can google more on this, google is your friend when you know what to google for) are:

Pseudocode is an informal language that helps developers write algorithms. It is a text-based design tool and it uses a human-readable language. It’s a structured english text that describes an algorithm.

Every Algorithm in Free Code Camp curriculum can be solved using pseudocode and after that translated using javascript in a functional javascript code.

11 Likes

# How to Start When you are Stuck Part 2

Let’s try an example. If we take a look at one of the Free Code Camp exercices, and let’s choose a more simple one: find the longest word in a string. We can start and draw a flowchart for it and write a first solution in pseudocode.

So what does Free Code Camp want from us with this problem? Well it wants us to create a function that gets a string as a parameter and returns an integer. This integer should represent the length of the longest word in this string. Usually you can solve a problem on Free Code Camp by just looking at the More information text. In this case Free code camp is giving us some very good tips:

Return the length of the longest word in the provided sentence. Your response should be a number. Remember to use RSAP if you get stuck. Try to pair program. Write your own code. Here are some helpful links: String.split(), String.length

If we take a look at the Free Code Camp suggestions we’ll see that String.split() can be used to split a string into an array and String.length gives us the length of a string. This helps us think of an algorithm. What if we split the string into an array, we loop through it and using the length attribute we find out the length of the longest word. Hmm, doesn’t seem very complicated but how to start this? Well … take a look at the image below.

If we follow the schema AND/OR the pseudocode, writing the function that gives us the length of the longest word in a string shouldn’t be very hard now … in any language … not just in javascript.

Now that we have this first working version, we can try and rewrite it using a for loop. Or we can take a look at forEach and if we really want to go wild we can rewrite this using the functional programming way. So let’s challenge ourselves to write a “one line” solution for the problem.

Searching through the MDN documentation you’ll find out that you can use the max function on arrays and that there is a map function that helps us change the current array. Hmm … that should should help us … right? Yes! the idea remains the same, you get a string, split it into an array and you return an integer but here is how:

4 Likes

# How to Start When you are Stuck Part 3

### Tips

• Always look at your logs, keep your console open. You can spot errors faster this way. To open the console log on chrome: click right -> inspect -> console There are so many errors that come from typos and so much time lost that you can save just by developing this very simple habit
• Pair with other programmers as much as you can
• Read the documentation. You can install a very helpful MDN Chrome Extension and use it as much and often as you need to