A penny drops

Today’s efforts have elucidated a few issues for me. Firstly, arrays. For whatever reason, I hadn’t grasped that they’re packets of information. I was viewing them as sequences of numbers. Rather than seeing the numbers within an array and the instructions relating to that number specifically, ¬†instead its position within the array. So that’s a minor breakthrough for me.

Secondly, the evil FCC exercise that had been eluding me has become 2/3rds understandable. I now understand that:

variable x is initialised at 0 value, runs until the end of array called contacts and involves moving on 1 position after each loop.

Then, if during the loop, a first name matches a first name AND if property matches with a property, then you return the values of x(first name) and the property.

If it takes a subsequent loop and it finds a match just for a first name it returns, “No such property” and if it loops again and doesn’t find anything then “No such contact” is returned.

What I still don’t understand is the useage of ‘.firstName’ and ‘.hasOwnProperty’. I mean, I get what they stand for but I don’t know the use of the dots, nor where the hasOwnProperty bit arrived from. At least I’m not too worried and have a bit of faith that I’ll come across this in my textbook before it’s time to get back to FCC on Sunday.

Meantime, I’m going to watch the Harvard CS50 computing course videos on youtube. I’ve heard it’s really good at explaining how to think like a programmer. Ciao for now!

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.

Hitting a brick wall

In going through the FCC challenges, there have been times I’ve given in to looking at a hint after a few hours of no progress but I’ve been able to figure out the working and I’ve been able to move on. I might be being somewhat over-dramatic but I think I’ve found my nemesis and it’s got me in a choke hold and is pummeling my face…Nesting for loops.

I was doing okay with iterating odd/even numbers as well as counting backwards. But pop an array in there and I’ve got a problem. The key thing I don’t understand which may, or may not, be the key to my problem is the [i] in the following:

var arr=(10,9,8,7,6)

for (var i=0; i <arr.length;i++) {

console.log(arr[i]);

}

I get that the variable is the top array. Then the loop initialises with the value 0. Then the condition is that it will continue cycling as for the length of the array as its maximum while adding 1 more ¬†every loop. Now, it’s meant to output each part of said array but I don’t really understand the relation between the array and that final [i]. I definitely need to go back a couple of lessons and thrash it out. Nesting for loops?! I’m coming for you!!!!!! p.s if you can explain it to me, you have a friend for life!