Having major problems with Javascript


#1

I need to commiserate with my fellow FCC’ers. I just do not get Javascript. I need a hug or something. Or motivation. I almost want to give up because it is like Greek to me. I understood HTML just fine, but this is absolutely kicking my butt


#2

Javascript is the first language that’s going to make you think like a developer. There are going to be a ton of challenges for you to go through… You’ll learn as you progress, little by little you’ll under the language more. HTML & CSS are way easier while javascript is an advanced language that does more exciting things. You are going to get frustrated, the important thing is to keep trying to learn day by day, practice, practice, and practice some more.

Is there a specific concept you need help with? We can try to help you better understand it. How far have you gotten through Javascript?


#3

HTML is markup (knowing the basic parts of a car).
CSS is style (painting the car).
JS is behavior (driving the car).

This is to be expected, especially if you’re new to coding in general. Back when I started learning web dev as a teenager, JS was what tripped me up and made me lose motivation. It’s only now, having learned a decent amount about how computers work and a little of various other programming languages, that I can finally get my head around it.

Another thing that helped is that now jQuery exists. Are you focusing on jQuery or pure JS? I found that jQuery allowed me to get a better understanding of JS at a coarser grained level, which then helped a lot once I wanted to go back to basics with pure JS.

If you’re already using jQuery and struggling with it, a good place to start is the official jQuery documentation itself. Try out a few experiments with something simple (click this button to make another element disappear. Then change your code so the button makes the element red instead. Then change the code again so it toggles the color between red and blue. Then make the animation slower. Then make it change the text of the element… Etc.)


#4

It just takes a lot of time and effort, a lot and I mean a lot more effort than simple HTML/CSS, it’s the first time you have to start thinking like a programmer and getting that new mindset and thought process is going to take time to get used to. But remember that you can do it.

The important thing is to keep trying everyday, don’t overwork yourself, and be persistent. Overtime you’ll learn. Even at like three months you are only just starting to truly work with javascript (with knowledge of all concepts), you’ll still be learning and working towards the goal.

If @awwsoclose would mind telling us what he/she is specifically having trouble understanding we’d be more able to help them understand it.

Remember @awwsoclose you can do it and you’ll get the hang of javascript soon.


#5

Hello everyone—

Thanks for the words of comfort. I’m currently on the palindromes and the longest word in the string challenges. I 95% understood the factorialize a number challenge. I go to the palindromes challenge and couldn’t find a way to remove punctuation. So then I tried the longest word. I tried splitting “str” into an array and every code I found online that counted letters wouldn’t work and then I couldn’t figure out a way to order them and find the highest. So then I came here, vented, and then watched some Hulu lol.


#6

You will need to use Javascript’s regular expression, regular expression is like a mini language complex but once you master it, it’s super useful.

str.replace(/[^0-9a-z]/gi, '')

That will leave only letters and numbers. That’s the first hint I’ll provide you :slight_smile:


#7

You can use the Javascript Regex event and do /[\W_\]/g, which removes all the non-word symbols. (You can check Regex out here https://www.w3schools.com/jsref/jsref_obj_regexp.asp)
You can try writing a for loop for the arr where you stored your words and push the length them into another array
Example:

        wordsLength.push(wordsArray[i].length);
   }```

Tbh when I first started learning Javascript I also found it really difficult, and these challenges usually took more than a day (I do like 1 ~ 2 hours per day). But as long as you keep coding, there's definitely gonna be a day where things just automatically starts to make sense!

#8

Sorry, I’m the type of person where people have to break out the crayons and construction paper. What exactly does it mean to “push” it onto another? wouldn’t that just add it onto the end of the same array?


#9

Alright, this is what I have so far

function palindrome(str) {
strOne = [str.replace(/[^0-9a-z]/gi,'').toLowerCase.split];
  strTwo = [strOne.reverse];
  if (strOne === strTwo){
    return true;
  } else {
    return false;
  }

Everything that should return false is returning false, but nothing is returning true


#10

I have annotated your code

function palindrome(str) {
// function calls need parentheses after the function name
// so toLowerCase() split() reverse() etc
// [...] creates an array - is that what you really want?
strOne = [str.replace(/[^0-9a-z]/gi,'').toLowerCase.split];
strTwo = [strOne.reverse];
// since your function always returns false the if condition must always be false
if (strOne === strTwo){
  return true;
} else {
  return false;
}

#11

Don’t worry. Every time I feel a bit discouraged about learning this stuff I remember how many great things you can make with the power of JavaScript and programming in general. So don’t be discouraged. Just keep learning and grinding and things will be better for you ;).


#12

What I’m trying to do is modify the str. I originally had it as:

str.replace(/[^0-9a-z]/gi,'').toLowerCase.split;
strOne.reverse;

However someone told me that I wasn’t storing my values anywhere. So I tried to create two new strings so that I can compare using “===”.


#13

You’re on the right track - saving the strings is right - just no need for a new array


#14

Take it step by step, do you have a whiteboard, large sheet of paper and markers, draw out the process of how your program needs to do the task and then little by little take those steps and turn it into code.


#16

Hi - just noticed one small thing missing… after .split you need to have parentheses. It should look like this:

strOne = [str.replace(/[^0-9a-z]/gi,'').toLowerCase.split(' ')];

The .split() method needs to have a ‘separator’ so to speak (in this case, at each space in the sentence), where you want it to split the string. Here’s the link on Mozilla Developer Network for String.split(). Especially note what the return value is:

Return value

An array of strings split at each point where the separator occurs in the given string.

And on the next line it should look like this:

strTwo = [strOne.reverse()];

Here’s the link for MDN array.reverse(). One more tip: you’ll need to most likely use Array.join() to re-join the strings together :slight_smile: Hope that helps!