5 easy and effective steps to finally code successfully from the scratch

So, I really want to talk about crossing the bridge from tutorial hell to programming

Now, as someone who started actively JavaScript in February, I'm nowhere near an expert

But I can guarantee that what you're about to read will help you finally start solving coding exercises and coding from scratch

So, every newbie coder experiences this. 

After taking tutorials, and learning about the syntaxes in a language. If you're like me, you probably coded along with a teacher.

However, when it comes to your turn to create something, from the scratch, it's as though your brain is blank

Now, the first thing you'd definitely see online when you browse how to be a problem solver is they'll tell you to "divide the problem into smaller problems" and then "Create a pseudo code for the problems"

That's it.

You're not told the next step. You're abandoned to figure out the next line of action.

Expert coders may not even realize when they finally grasped the concepts. Even them may not know when and how the problem solving finally clicked for them. 

That's why they probably don't know how to break it down explicitly on the next steps

I was stuck in this wormhole for the longest of times. Until I had this eureka moment. 

The truth is...

"The biggest block to coding from scratch is knowing the particular syntax that you should use. The exact logic that can work for the problem you want to solve."

Let's dive into examples.

Suppose you get this exercise - 

"Write a program that returns true is the sum of 2 integers equals to 100."

Best practices suggest you start with a pseudo-code

  • It means our program will accept 2 numbers as parameters
  • Add the two numbers in the parameters
  • If both equal to 100, return true

So at this point, if you've not mastered the core JavaScript building blocks, it will be difficult to know the very first step to take

Step 1. This is why the first question to ask yourself is...

What code in JavaScript accepts 2 parameters, that you can call on.

That gives you Function

So we have to create a function that accepts 2 parameters

function isSum100 (x, y) {


}

Step 2. The next question is...

What method in JavaScript adds two numbers together

You have the "+" maths operator. And that's what we'll add next

function isSum100 (x, y) {

  return x + y

}

Step 3. Okay, but remember, there is a condition. 

We have to check if adding both equals 100

And here comes the conditional statement - 

function isSum100 (x, y) {

  if ( x + y === 100) {

   return true 

}

And that's it.

Step 4. We can actually go a step further to add a statement in case both don't equal 100. 

That's where our else statement comes in

function isSum100 (x, y) {

  if ( x + y === 100) {

   return true 

} else {

return 'Numbers do not equal to 100'

}

}

Step 5. Now, it's time to call the function

IsSum100(20,80)

console.log(isSum100(20,80))

And that's it. We've successfully solved a problem using JavaScript.

I hope you find this the most helpful.



Comments

Popular posts from this blog

Passion

Notions (Wi-Fi)

Took so long