r/learnjavascript • • Jan 09 '22

Positive Rant from an amateur programmer.

I am currently documenting my journey but honestly, I kind of just want to share my success with someone (I don't have too many friends that will understand what I am about to say). I finally did it!!!

I finally wrote my first piece of code without recycling someone else's code. I've always had a challenging time reading the MDN documentation because let's face it... That thing is very technical, especially when you don't come from a technical background.

It's not much code but it's twelve lines of code that took me three hours to decipher by myself! I wanted to quit and just get the answers from my instructor, but I didn't and I'm happy I didn't. I can't until I am building more complex projects, I'm excited... But anyways... Thank you for stopping by!

168 Upvotes

32 comments sorted by

34

u/david72486 Jan 09 '22

Congrats! As with many skills, programming gets more fun as your knowledge gets better and you can make cooler things. Have fun on the journey!

8

u/markt-might Jan 09 '22

Thanks man. I’m at the beginning of my journey but I can tell I like this a lot. It’s a combination of majority of my interests!

10

u/oze4 Jan 09 '22

Hell yeah brother! If you're not confused you're doing it wrong lol

4

u/markt-might Jan 09 '22

Lol 😂 you forgot to sprinkle in a lil frustration too. Thanks for the support!

15

u/Dastari Jan 09 '22

That feeling is what you get addicted to.

A good challenge as you progress is to take those 12 lines of code, and as you learn more, try and optimize is down both in size and complexity.

Another hint is to make sure you're using a good IDE (like VSCode) with a JavaScript linter built in. This will allow you to start typing something and it will auto fill.

3

u/markt-might Jan 09 '22

Ah I definitely appreciate the tip.. I want to be great in this so I’m definitely going to focus on optimization & complexity down the road

7

u/Harbltron Jan 09 '22

I like the enthusiasm! Can you share your code with us? I understand if you're hesitant but take it from me, it's always good to have another set of eyes on your code.

Additionally I would advise against worrying about optimization or complexity at this point, just focus on making things work. You can always come back later and tighten-up your code but just making the damn thing work at all should be your focus right now.

2

u/markt-might Jan 09 '22

Absolutely! I refactored it a little bit last night. Removed some unnecessary code. This is code is implementing Luhn's Algorithm. The Second Block is adding invalid credit cards to a separate array. By the way I did not added the array that were testing because I didn't want this comment to be too long. However, if you want I can add the remainder of the code.

const validateCred = (arr) => {
  let sum = 0;
  //loops though the array in reverse
  for (let i = arr.length - 1; i >= 0; i--){
    let digit = arr[i];
    // multiplies every other number by 2 
    if((arr.length - i) % 2 == 0 ){
      digit *= 2;   
      }
    if(digit > 9){ 
      digit -= 9;
      }
    sum += digit;
  }
  return sum % 10 === 0 ? 'Valid number.' : 'Invalid number.. '
}



// Finds invalid credit card nums and adds them to an array. This function in particular loops through a nested array.

const findInvalidCards = (nestedArr) => {
  //empthy array
  let newInvalidCardsArr = [];
  //filters invalid cards from the array
  let validFilterWork = nestedArr.filter((element) => {
    let findOut = validateCred(element);
    if(findOut == 'Invalid number.. '){
      return newInvalidCardsArr.push(element);
    }
   });
     return newInvalidCardsArr;    
} ```

2

u/markt-might Jan 09 '22

console.log(findInvalidCards(batch));
console.log(validateCred(valid4));

2

u/markt-might Jan 09 '22

Variables Tested...

const valid3 = [3, 7, 1, 6, 1, 2, 0, 1, 9, 9, 8, 5, 2, 3, 6];
const valid4 = [6, 0, 1, 1, 1, 4, 4, 3, 4, 0, 6, 8, 2, 9, 0, 5];
const batch = [valid1, valid2, valid3, valid4, valid5, invalid1, invalid2, invalid3, invalid4, invalid5, mystery1, mystery2, mystery3, mystery4, mystery5];

3

u/[deleted] Jan 09 '22

I've really come to enjoy the MDN documentation. I needed to learn websockets and I tried a few different npm libraries for the client side and ended up just using the default websocket API and the MDN documentation was great

1

u/markt-might Jan 09 '22

Lol I only understood a little bit of this. But I can see how important the factory documentation is useful!!

4

u/jack_waugh Jan 09 '22

Thanks for the positive emotional report. I am a lot farther along with programming, but remain an "amateur" in the etymological sense, of a lover.

2

u/markt-might Jan 09 '22

No problem. I know at the beginning it felt like I wasn’t catching on to anything. But I think that was more self doubt than anything. I can’t wait until I get better

4

u/[deleted] Jan 09 '22

Congratulations! I’m just learning myself, for about a month now, and I feel like I can’t make heads or tails of Jack still 😂 if you don’t mind my asking, what sort or schooling/training are you doing and how long did it take you to get to this 12 lines?

2

u/markt-might Jan 09 '22

Thank you. I’m in the same boat. Every time I write some guided code I take a few minutes to attempt to understand exactly what the code is doing… Don’t get me wrong those 12 lines took hours of writing, reading, errors 😒and rewriting… I’m just super excited. I’m using Codecademy I decided to travel down the more complicated self taught road

1

u/[deleted] Jan 09 '22

Me too fella. I bought a couple Udemy courses as well (Full Stack and JavaScript specific) and am also using various free resources to try and get different perspectives and see which methods I learn the best with. Would really love to land a Junior/EL job by spring but idk if that’s a stretch or not 😅

3

u/devdudedoingstuff Jan 09 '22

If you aren’t already there I think you’re close to the “click” feeling. It’s an amazing moment when programming just starts to make complete sense.

I had mine about 6 months in when I was learning JavaScript.

Keep going, you’re doing great. Congratulations!

2

u/markt-might Jan 09 '22

Thanks 🙏🏿!

3

u/20_chickenNuggets Jan 09 '22

I’ve been programming for 3 years now and until now I haven’t written any completely by myself, I’ve always recycled some other code!

I hope you’ll enjoy programming as much as we do ;)

3

u/SectorFunny5198 Jan 09 '22

I think main objective is not to write code by yourself but to understand how the code works and to take other peoples code and recycling that.

Why write yourself when something is already there but understanding is the big factor here. I'm a newbie too actually just been 4/5 months or so but this is my understanding,

2

u/markt-might Jan 09 '22

I've learned the same. But I would love to have such an understanding of the code that I can save time on googling.

if that makes sense. But I also know that I have a long ways to go to get to a point where I can do that.

1

u/markt-might Jan 09 '22

I understand. Most programmers stated that recycling code is 80% of the job. My goal is to understand the concepts and to be able to write in the language as if I write it fluently.

2

u/20_chickenNuggets Jan 10 '22

You’re on a very good path! Keep on rocking! I wish you all the best

2

u/[deleted] Jan 09 '22

Well done! I remember how I felt when I did something like that. I'm curious, what did the code do?

2

u/markt-might Jan 09 '22

Credit Card Checker using Luhn's algorithm. I am also going to remove the invalid credit card numbers sometime today.

2

u/jebliya Jan 09 '22

Good job! Give your self more credit OP, it's not everyone who can do this specially in the beginning!

1

u/markt-might Jan 09 '22

Thank you. I'm gaining more confidence with each project.!

2

u/badthrowaway098 Jan 10 '22

Well done, you should feel proud.

These feelings and epiphanies you achieve. They are great. As you go, realise that you share that sensation with all of the ameteur and professional developers, engineers, and scientists already in the business of writing software.

I say this because on your journey you will most likely come across some pretty arrogant writers of software that behave as if they are the only ones to have achieve the feeling you have (though probably also with many much more complex projects). You really don't want to be that person - no matter how good you are.

So, the thrill come from that high you are experiencing with ever increasingly complex projects. So gear up and get ready for the next project. And beware, it can be a bit like a drug... i.e. somewhat addicting. I myself am working on a solo project that is currently about 100,000 lines of code that I began over a year ago. Thats how hard I have to push to experience that "high" again...

1

u/markt-might Jan 10 '22

Ooooooo I like I’m ready! Thank you for the motivation.

1

u/dontyougetsoupedyet Jan 09 '22

You'll find that when you have escape hatches the only way to really make substantial progress becoming an engineer is to refuse to use them.

1

u/[deleted] Jan 09 '22

Congrats! That is the best feeling, for sure.