Finally, understanding!

Hello, folks.

Been in a JavaScript personal hell what little self-confidence disappeared and I’ve flopped around like a fish out of water. However, I have, finally, managed to fully understand that Profile Lookup FCC challenge. So, here goes for a walk through:

We start out with x initialised at 0, moving as far as the end of the contacts list and moving on one at a time. Now, if the value of firstNames is a match, and the property value also has a match, you return both the first name and the property.

But if only the property has a match, you return “No such contact”. Then finally, if there’s only a firstName match, you return, “No such property”.

All of this is very similar to the original instructions which I completely over thought. I also didn’t allow myself to thoroughly go through my notes which would have helped a lot. So, while I’m still the odd bit or bob off trying again without notes, I get what my mistakes are and why they’re wrong. So that’s a wee bit of progress.

Next up is a session on Object Oriented and Functional Programming. Then a big, big 50 hour chunk of basic algorithms in  long list of problems to solve. I’m looking forward to the new challenges but I’m concerned I won’t manage them. I feel like I’m hitting a natural boulder of ability that I’m not going to get beyond. I really need to get building another website so I don’t forget those basic skills while I try to obtain a different set of basic skills.

Do you ever doubt you’ll reach your big goal? Do you have any mental tricks to get past those doubts?

Advertisements

DUM, DUM, DOM!

Back on the books tonight and the rest of the DOM chapter. It was about using the Document Object Model to make buttons to move your browser back and forwards history-wise, make text disappear and reappear and also add text typed into a box to show further up the page. ‘Dynamically’ as they say. I’ve found the explanations really hard to visualise. While typing out the examples does certainly help, there’s tons of code that I can only hope I’m only meant to have a vague knowledge of rather than actually know off by heart (I hope). Tomorrow should bring variables, strings and arrays so hopefully more familiar territory.

Switching causing violent twitching!

The basic JavaScript section continues slowly. It started off with simple addition/subtraction etc. But now has gone into the logic side of things using ‘If’ ‘else’ statements. Now, that’s not too hard if you remember where to put your brackets and semi-colons. Then came a more involved task that involved using a switch statement to create a blackjack decision making tool. These are (slightly) simplified version of if/else which is less wordy but does the same job.  However, the task didn’t specifically say that you needed to use a switch statement. As you needed to go back through the unit to the more basic concepts (pre-switch) it didn’t occur to me that there’d be a problem doing it long-hand.

However, there seems to be a divide between those who successfully managed the job with switch and those who tried to do it otherwise and failed miserably, like myself. For reference/in case you’re interested, here’s the solution.  I tried to redo the task myself using Switch before I totally succumbed to the full answer and I wasn’t using the ++ or — operators. I had understood the task but not the ‘how to’ although the answer does make complete sense. I can only hope that this is a minor hiccup…

This is the answer:

function cc(card) 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”; }

Look how tiny and pretty it is!