Am I just not cut out for coding?

Been studying and working on coding for about 3 months now, finished the free courses on HTML, CSS and JavaScript in Codecademy and now I’m here.Sailed through the HTML and CSS portions here at freeCodeCamp, but now I feel like I’m getting stuck a lot in JavaScript, mostly just the challenges like the “Convert Celsius to Fahrenheit”, “Stand in Line”, and most recently “Counting Cards”. I figure them out mostly on my own but, get really stuck on simple things that I should already know for example here’s my code for “Counting Cards”:

var count = 0;

function cc(card) {
  // Only change code below this line
  var decision;
  switch (card) {
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
      count = count + 1;
      break;
    case 7:
    case 8:
    case 9:
      count = count + 0;
      break;
    case 10:
    case "J":
    case "Q":
    case "K":
    case "A":
      count = count - 1;
      break;
  } if (count > 0) {
    decision = "Bet";
  } else {
    decision = "Hold";
  }
  
  return (count + " " + decision);
  // Only change code above this line
}

First of all I created an unnecessary variable called “decision”, I did not use the shorter cleaner versions of count++;, and also added the 7, 8, 9 cases which weren’t needed, Not only this but, I didn’t even figure out the code myself I had to get help from someone to hint to me that I needed to return a concatenated string because I kept returning an array. [count, decision];

If I can’t figure out simple stuff like this, how am I going to become a professional and make this my career? I know this isn’t even the tip of the iceberg either, haven’t even gotten to the algorithm challenges yet…should I just move on to something else and not waste my time?

4 Likes

I think 3 months is WAY too early to be drawing conclusions that you’re not cut out. I’m about 6 months in myself… definitely doubting myself in many ways, but this is a lifelong decision for me. I enjoy coding. I want to be good at coding. I want to do this the rest of my life. 3 months…6 months… 1 year… it’s nothing. Think about how good we’ll be in 5 years…

11 Likes

Much like solving difficult math problems, or learning to ride a bike, programming is a skill that you can constantly improve on with practice. While 3 months might feel like a long time, it does take a while to start noticing little things (like the ++ vs count + 1) that you can improve on. Even at a career level, there will still probably be times when you find that there might be a better way to do something than what you initially did. The most important thing is to recognize that there might be cleaner or better ways, and then try to implement them next time.

As for the unnecessary variable, you might look into creating a diagram or sudo code algorithm before you approach a problem. It will help you look for flaws in your algorithms before you start coding, and help you remove unnecessary things before you create a solution. I use to find that I had a lot of unused variables before I started trying to do this (not that I still don’t do it every once in a while).

Additionally, on the subject of asking for help, there’s no reason to feel shame in that. Chances are, if you work at any kind of company for your career, you’re going to be put on a team of developers. The biggest advantage of this is so that you can all help one another out. On top of that, you might be asked to work on something that you have no experience with, and so you’ll probably have to go find help to get you up to speed on that as well.

TL;DR - Don’t sweat having issues especially if you’re only 3 months in. No matter what level someone is at, there’s always something new to learn. If you truly find joy in programming, then you should definitely continue learning.

4 Likes

Your code for the “Counting Cards” is way overcomplicated, and doesn’t need a switch-case at all. Not sure why you thought you needed to use a switch-case. When you tackle a challenge, I’d suggest reading the problem description slowly and digesting it a line at a time, and then translating the description to pseudocode. So let’s do that starting with the problem description:

You will write a card counting function. It will receive a card parameter and increment or decrement the global count variable according to the card’s value (see table). The function will then return a string with the current count and the string “Bet” if the count is positive, or “Hold” if the count is zero or negative. The current count and the player’s decision (“Bet” or “Hold”) should be separated by a single space.

In other words, putting that into a form of pseudocode your solution might start like this:

if the value of the card parameter is between 2 and 6
    then increment the count variable
or if the value of the card parameter is between 7 and 9
    then do nothing to the count variable
or if the value of the card parameter is 10, J, Q, K, or A
    then decrement the count variable

if count is positive,
    then return a string with the current count plus the string "Bet" separated by a single space
otherwise,
    return a string with the current count plus the string "Hold" separated by a single space

There’s nothing complicated here and it’s just as simple as that. If you can’t go from the problem description to what I just posted above, then just think about each problem more slowly, and never overcomplicate anything. The challenges on FCC aren’t out to trick you, like some other sites would do. Everything is very straightforward. If you need to use something, or should use something, there’s usually a Hint. And if you don’t see a hint, then you’re thinking about it too hard.

Also, if you ever find yourself writing a “case” statement cascade as you did, you’re probably doing it wrong because switch-case isn’t supposed to be used that way. Usually you won’t have more than a few case statements in a switch-case block. And if you start writing a “case” cascade that’s getting to more than several items, it’s time to revert to the “if” statement.

Basically, a switch-case block is supposed to look simpler than an equivalent “if” block with multiple “else ifs” in the scenarios where it’s appropriate. Whenever your switch-case block starts looking that ugly, you might think about reverting to if/else-if instead.

4 Likes

huh… so like this:

var count = 0;

function cc(card) {
// Only change code below this line
if (card >= 2 && card <= 6) {
count++;
} else if (card === 10 || card === “J” || card === “Q” || card === “K” || card === “A”) {
count–;
} if (count > 0) {
return count + " Bet";
} else {
return count + " Hold";
}

// Only change code above this line
}

that solution worked too…never thought to put it out in sentences like that, thanks guys lot of good info here.

There’s nothing either wrong or overly-complex about using a switch case for this exercise. In fact, this exercise is 3 steps after the “Replace If Else Chains With Switch” exercise, in which it’s explained that a switch case can be useful when you know there are a small finite number of possible responses, so it’s perfectly reasonable to understand why someone going through these exercises would approach it using switch.

That’s not to say if/else can’t or shouldn’t be used, but it’s to say that there’s no reason switch can’t or shouldn’t be used either – it should really be a matter of preference.

In any case, ROBUSTO8, here is the switch solution I used for the Counting Cards exercise. Either switch or if/else are acceptable, it’s really your preference:


var count = 0;

function cc(card) {
  // Only change code below this line
  switch (card) {
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
      count++;
      break;
    case 10:
    case 'J':
    case 'Q':
    case 'K':
    case 'A':
      count--;
      break;
  }
  if(count > 0) {
    return count + " Bet";
  }
  else {
  return count + " Hold";
  }
  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');

As to your initial post, just be patient, let it saturate naturally – everything ryanjgross said is spot-on. Keep on keepin’ on! :slight_smile:

1 Like

I have been coding, since about 2000 (off and on). I have Delphi, Basic, Fortan, C, C++, A little Java, I stared at Python once (nice language but the code block make me mental) and of course JavaScript, CSS, HTML, SQL (in MySQL, MSSQL, a touch of Oracle 8i, dBase, Paradox and more)…

…and I still make mistakes, dumb ones too. I have even managed to take a site down because I added a semi-colon to the end of a line of htaccess…spoiler alert! don’t do that!

But you will, and I will, and every one will make mistakes and write dumb code. Don’t worry about it, it is all a part of learning. I tell you what, when you are feeling bummed out and you want to quit, think about babies.

Yeah sure they are cute and all, but watch a baby learn to sit upright, crawl, stand and finally walk and run. They did not start out walking, they worked on it and never gave up. And they make a lot of mistakes along the way. If you think about it, that’s life. A grand series of mistakes until we get it right, mainly because of persistence. So hang in there your still learning to crawl.

6 Likes

Yeah, that’s what my code should look like cleaned up :+1:

1 Like

If you’re curious, this is how I just did it:

spoiler
var count = 0;

function cc(card) {
  // Only change code below this line
  count += (typeof card !== 'number' || card > 9) ? -1 : (card <= 6) ? 1 : 0;
  return count + " " + ((count > 0) ? "Bet" : "Hold");
  // Only change code above this line
}


// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');

Which is really doing the same thing but ultimately is harder to read than yours!

3 Likes

Don’t get down on yourself! I struggled through the checkpoints in js, but the important part is going back through the lessons afterwards and making sure that you really understand it. Keep coding, keep learning!

2 Likes

Thanks heaps for writing this post. I’m doing C over at CS50x and I was thinking the same as you, “am i cut out for this s#!t”. Reading the great comments here has helped heaps in my not sweating the small stuff. A couple of months coding feels like a long time but it’s nothing and doubt is naturally going to creep in occasionally. I think the best way to measure how your going is to not compare yourself with others but to compare yourself to you and how good you are now as opposed to when you started. Stick with it as I’ve been told constantly that at some point everything will just “click” into place and make total sense. I get down on myself because I haven’t had that “aha!” moment. I’ve had plenty of little ones but if we gave up every time we had doubts, we wouldn’t accomplish anything. I’m sure you are much better at coding now, than you were at the beginning, so you have made progress :wink:

4 Likes

Ryan–as another brand-new coder (less than 3 months), it’s extremely reassuring, seriously, to know that even developers with your level of experience can still run into walls. (I say this after I just spent an hour wrestling with a simple HTML/CSS problem that turned out to have a 30-second solution.) Thanks for this.

2 Likes

Get that thought out of your head.
I consider myself to be junior level and everyday I learn how to improve my code. When I first started on freecodecamp I made a for loop iterating an array instead of accessing it like arr[5].
Sign up to Codewars.com. You will solve many problems and see how your answers are less effective than others. Then, you’ll learn their way of thinking and start figuring out better ways on your own. After you feel ready enough - go back to FCC and see how simple it is for you to solve those problems
Good luck!

2 Likes

Sorry, I disagree with your premise that his code is overly-complicated (or wrong).

You might not like the choices made, but that’s a style issue. I, for instance, can’t stand multiple if-elseif statements. That is EXACTLY what switch is intended to solve.

1 Like

Don’t give up! JavaScript is NOT intuitive at all. But it will get easier with practice. YOU CAN DO IT :slight_smile:

1 Like

I’ve been coding - off and on - for 36yrs (though relatively new to Javascript) and mistakes are how you learn - in fact making and fixing mistakes it what makes coding fun. If it were just a matter of typing in code and getting it right first time then it would be about as exciting as a data entry exercise. There are many of ways to solve the same problem - only 2 real questions - does it work and does it make sense to the next person who reads your code? (which may well be just you but when you look back at code you’ve written a few years ago you realise how it might look to someone else!) Anyone who writes perfect code first time is either a genius or ‘thinks’ they are.:slight_smile:

4 Likes

Let me just say this struck a nerve with me, because sometimes I still feel this way, and I’ve been the lead front-end developer for a sizable Ember app for 2 years. Especially as I know there’s so much I don’t know! I’m working through the curriculum right now too, and have occasionally felt like I should just know something off the top of my head, but I don’t, and that’s ok. I search out an answer, and learn something new. Also, you probably know more than you think; we all struggle. Ignorance is bliss I. Some cases, as the more you learn, the more you see what more you can learn, and you become familiar with those who are really good at JS and think you’ll never get there.

But if it’s interesting to you, keep it up. I would recommend the online book “You Dont Know JS”, and this article is chock-a-block full of resources: “10 Priceless Resources for JavaScript Learners” https://medium.com/javascript-scene/10-priceless-resources-for-javascript-learners-bbf2f7d7f84e

If you need help on any exercises, or questions on JS, I’m happy to answer if I can, hit me up any time on Twitter @jessdhines.

3 Likes

[quote=“whipdancer, post:15, topic:100991, full:true”]Sorry, I disagree with your premise that his code is overly-complicated (or wrong).

You might not like the choices made, but that’s a style issue. I, for instance, can’t stand multiple if-elseif statements. That is EXACTLY what switch is intended to solve.[/quote]

Sure, there are individual preferences, but there are also objective metrics by which to judge how good your code is (size, speed, correctness, and readability, the last of which is somewhat subjective but can be judged by objective tests of how quickly and accurately others can understand it).

Something like “single vs. double quotes” or “tabs or spaces” are more subjective (though even then they may have effects on some of the objective metrics).

I guess the only fully subjective qualities are things like how “beautiful” your code is, and that is truly in the eye of the beholder.

When I used to teach ski school we would tell students (especially adults) that if you weren’t falling, you weren’t learning. The reason that we had to tell this to adult students is that as adults we see “falling” as failing. Whether we are talking about skiing or coding mistakes are how we all learn. Its part of our nature to try something, see what doesn’t work and then try something new. It’s through the repetition of doing this that we learn.

I have been programming off and on since the mid-80’s started on a TRS-80 but just started with Javascript a couple of years ago and was thrown into the deep end on a project as I am not a professional software developer but a challenge at work came up and I was asked to solve it. It was developing a real time dashboard for a machine that we had in the manufacturing plant that used Angular and Firebase. Holy crap did I make a lot of mistakes but I learned. I have since then moved onto a start-up that I co-founded where I code in Node.js most days. I have rewritten the code base for the device I am responsible for 3 times so far, each time it gets better, more performant and easier to maintain/upgrade.

I am working my way through the material on Free Code Camp because I would like to become a better developer with a better understanding especially of the front-end as the one front-end project that I worked on was hacked together, it worked but man was it ugly. I hace spent the last 3 years writing node that runs on an embedded device so even though I know node pretty well I have never really used it to develop back-end code so looking forward to learning that and making lots of mistakes along the way. Another thing that I have been trying to get better at is writing tests for my code so that I know when we make upgrades we aren’t breaking something somewhere else. I have been using the TDD lessons at exercism.io to get better at testing which is another good way to solve these challenges, if you can write code that passes the test, even if its ugly you can figure out how to make it cleaner and still pass the tests.

Long way to say, just keep trying and know that it takes years to master this stuff. I still look up stupid simple stuff on a regular basis because let’s be honest, its a lot to just remember. The most improtant thing that I remember from being in school for engineering is NOT to try to remember everything, know where to go find the answer and how to read the answer. Trying to remember everything is how major mistakes occur.

3 Likes

If you enjoy the moments when frustration becomes A-HA moment, and you learn something that you couldn’t understand a couple of minutes/hours/days/weeks ago, then stick with it.

I’m 6 months into the whole web programming thing, I am a slow learner, and I suck at most things I do even today, but I enjoy it and even if I get just a tiny little bit better than I was yesterday, I call it a good day.

It’s hard, but it is rewarding, both as a career and as a hobby.
Enjoy learning, and creating and making beatiful things with the knowledge that you gain. Do not compare yourself to others a lot, compare yourself to your yesterdays self and keep on coding!

5 Likes