Beginner programmer struggles

Hello all!
I have been following some courses and am still enjoying them. I would really like to progress through the programmer courses to get myself a decent programming base.

But as a complete beginner programmer I am struggling a lot more then I was hoping I would with the most basic course.

I am following the basic Javascript course, but I am stuck at the looping part for a couple of days already. As soon as I let go of the course or tutorial literally nothing I try to achieve works.
Every day I put multiple hours in and still I am stuck on the complete basic, and I am running out of ideas how to get past it at this point.

I have been checking out many different sources online to see if a different perspective could work, but as soon as I get back to try and write something myself, it just fails.
Also the first practice exercises in the course were obviously no success and I couldn’t get even close to getting it those to work.
Am I the only one that’s struggling this much with just getting down the basics??

Is there maybe some easy practice projects I could try to work on to give me some goal to work towards?

Any tips are appreciated !

Thomas

1 Like

Hi Thomas,

You say that whatever you write “just fails”. What does that mean? You don’t know where to start? Or your code doesn’t execute? Or you get errors? Or your code runs, but doesn’t produce the results you were expecting?

These things can have different causes, we would need some concrete examples to help you out.

Code not executing could be a syntax error. Maybe a missing (closing) tag, or your parentheses/brackets don’t match? Or maybe your function is correct, but you forgot to call it?

Error messages could be syntax errors. Or maybe you’re using a variable that wasn’t declared yet?

Code that runs but doesn’t produce the desired result is often caused by faulty logic in the instructions.
Without specifics it’s a bit hard to help…

Usually a search on google and/or youtube should provide some help. There’s tons of resources out there, not just tutorials, but also examples and exercises. A search on “javascript loop exercise” produced several links with examples and exercises.
Try different sites, it might take some time before you find a resource that explains things in a way that you understand.

What I find helpful while learning is that before trying to build something myself, I try to recreate the examples that were giving. When Ivan is typing code, I type it too. This helps me notice details in the syntax that I would have missed otherwise. If the example works, then I try to make it again, this time without looking. Only then do I attempt the exercises.

Also, pay attention to the syntax highlighting in your editor. When the colors of your code are suddenly wrong, it’s probably because of a typo or a tag/quote/bracket that hasn’t been properly closed.

Adding console.log messages in your code can help you figure out where the error occurs.
eg in an if-else block you could do this:
if (condition) {
console.log(“i’m in IF”); // <-- this line tells you that you entered this code block
//your code
} else {
console.log(“i’m in ELSE”); // <-- same with this line
//your code
}

Or for a loop:
for (i=0;i<5;i++) {
console.log(“i’m in the for loop, i=” + i); // <-- tells you whether you entered the loop or not
//your code
}

These are just some random ideas, we would need specific examples to help you further.

May the force be with you!
Wayan

1 Like

Thanks so much for the detailed reply! I should have given some examples you are right. When I run into more problems I will provide them in this thread.

Hello !
I’m at the moment trying to figure out the linear search of an array.
I manage to somehow get it to work, but not completely how I wanted it to.
There is a few things I cannot seem to figure out:

  • Why did the n.length approach not work? Is there a way I can make it work that way?

  • I wanted the counting to start from 1 instead of 0, 1, 2 etc. But with i=1 the first number will not show up on the search and doesn’t change the way of counting.

  • If I want to change from a numeric variable to a string my approach doesn’t work.

My first approach was

for (var i = 1; i <= n.length; i++){

Then I changed to this:

var a = [6, 5, 7, 3, 8];
//array with numbers
var n = 5;
//amount of numbers in array
var x = 6;
//number to be found in array
var answer = "NOT-FOUND";

for (var i = 0; i <= a.length; i++){
  if (a[i] == x){
    answer = i;
    console.log(answer);
  }
}

Any help would be appreciated ! :slight_smile:

p.s. I know the n = 5 is useless, but I left it there for reference.

Why did the n.length approach not work?

That’s hard to say if you don’t tell us what n is. Is it an array or a number?
It’s also hard to say if we don’t know what the result was. Did your code run? Did you get an error? In what way was the result different from what you expected?

If n was a number, then n.length doesn’t exist, numbers don’t have a length, arrays and strings do.

I wanted the counting to start from 1 instead of 0,

Computers do things their own way, and they start counting from 0. Don’t fight it, you’ll lose. The first element in an array has index = 0, so if you start counting elements starting from index = 1, then indeed you will not count the first element.

for (var i = 0; i <= a.length; i++)

You’re confusing the length of an array with the indexes of the elements in the array. An array with 5 elements will have length=5, but it’s elements will have indexes 0 to 4, not 0 to 5.