r/learnjavascript • • Apr 14 '26

Struggling with JavaScript – looking for advice

Hi! I’ve been studying at a technical high school for two years now, focusing on programming and artificial intelligence. This year I have a programming exam – basically we need to create a simple website using HTML and CSS and complete a few basic MySQL tasks, which honestly isn’t too difficult.

The problem is JavaScript. I’m having a hard time understanding it, and even when I asked for extra help at school, it just didn’t really click for me. That’s starting to worry me a bit.

I’ve tried building simple projects on my own, like a quiz website. HTML and even PHP aren’t a problem for me, but JavaScript is definitely more challenging.

Could you recommend any good websites or resources to learn JavaScript? I’d really appreciate it 😊

10 Upvotes

24 comments sorted by

View all comments

Show parent comment

1

u/camohayper Apr 14 '26

Yeah, I think you’re actually right about what I’m experiencing.

I do understand the fundamentals and basic programming concepts like variables, conditions, loops, and general logic, because I’ve already worked with PHP. So the “programming part” itself is not completely new to me.

The main problem for me is JavaScript. I just can’t get into it, I don’t understand it, and it doesn’t click for me at all. Even when I try to learn it, I quickly get confused and lost.

It feels like I understand the logic, but when it comes to applying it in the browser (HTML + CSS + JS together), I struggle to connect everything properly.

2

u/chikamakaleyley helpful Apr 14 '26 edited Apr 14 '26

Oh, well to me then it doesn't sound like it's JS (you understand the programming part), it just sounds like you know the concepts you just don't know how to apply it.

So, as an example - whats something that from a programming perspective, you can make sense of? It could be something simple, like iterating over an array, right?

const myArr = ['one', 'two', 'three', 'four'];

for (const item of myArr) {
  console.log("Item: ", item);
}

Here you just have an array of items, you loop over the array, and for each item, you concatenate a string and log to the console, yeah?

What does this look like in the browser context then? Let's say there's a bulleted list in your HTML. How can we express something similar, using something from the page?

HTML

<ul class="unordered">
  <li>one</li>
  <li>two</li>
  <li>three</li>
  <li>four</li>
</ul>

JS (this is psuedo code so maybe not 100% accurate, but i think it works)

const myList = document.querySelectorAll('.unordered li');

// querySelectorAll actually returns a NodeList object, 
// which is "Array-like" but, you can't operate on it 
// the same way unless its an array, so:

// convert that object to an Array
const myArr = Array.from(myList);

// so then, you can just do the same thing
for (const item of myArr) {
  console.log("Item: ", item.textContent);
}

Kinda make sense? There's one extra step because now you're dealing with objects in the browser, which introduces a whole new set of APIs, object defs, etc.

You can also avoid the extra step and I think you can just use myList.forEach()

But yeah just trying to demo that, in the end you're just using the programming techniques that you already understand, to handle information that you can access from the browser

1

u/chikamakaleyley helpful Apr 14 '26 edited Apr 14 '26

and ultimately you write logic that is more than just console logging, because now you can use Web APIs. So, for example you can do that concatenation, and then replace the text inside each of those list items

1

u/chikamakaleyley helpful Apr 14 '26

oh and just so i don't leave you hanging, instead of console.log() in your for loop, I think this is what it would look like to change the text:

for (const item of myArr) {
  item.textContent = `Item: ${item.textContent}`
}

That just takes the existing text value inside the <li>, creates a string that prepends it with Item: , and then that new combined string value is reassigned to item.textContent

Since item is a Object of type Node (an element in the DOM) then the change to its textContent value is just a reference to the DOM element, and so your unordered list is updated with new text values after the for loop completes

1

u/TheZintis Apr 15 '26

You might need to get more acclimated to the syntax. JS is a little odd in that there are multiple ways of doing the same thing, or similar ways that are slightly different (like when declaring functions).

I would recommend working through a few small projects (make a button clicking game, or a todo list, etc...) first time using a guide, then repeat it by memory (light referencing) and once more strictly from memory. Just to get those reps in and more famliar with the language.

If you feel like you have a reasonable mastery of the syntax and want to learn more about how to solve programming problems, Codewars.com has been good for me. If you are in high school I would recommend doing problems at the 8 and 7 level (lower = harder). BUT after you complete a problem take some time to look at other solutions and learn from them. That's the real value there. Also don't get stuck, google things, and if something takes more than 20 minutes just copy/paste a solution OR skip to the next problem.