Awesome teamwork today! We covered a lot, and I am really proud to see how beautifully you cooperate and try to help each other! Also, please, do remember that you need time, practice and rest to let everything sink in, so itâs perfectly normal if it feels confusing and a lot. Because it is!
Quick reminder about homework for the next session!
Tomorrow weâll start with the ES6 section, so your homework is to do the exercises until that point and finish basic Javascript module!
Remember folks, youâre not alone.
Donât hesitate to seek help in the js-help channel or on the forum!
Be sure to collaborate, stay hydrated and get plenty of rest!!!
Weâre all in this together!
Happy Coding!
#PatPatđ¤
Hello everyone - RamĂłn, thanks for the excellent tuition!
I have a question about the record collection exercise - this is the nth time I have tried it, and I am getting better at it. I now have a solution which works - but only if I have included console.logs - itâs very strange to me, as I believe console.logs are not part of the program, but are just there to illustrate what is happening as the program runs, by displaying the contents to the console.
Here is my code
function updateRecords(records, id, prop, value) {
console.log(records[id])
if (prop !== âtracksâ && value !== ââ) {
records[id][prop] = value;
} else if (prop === âtracksâ && !records[id].hasOwnProperty(âtracksâ)) {
records[id].tracks = [value];
} else if (prop === âtracksâ && value !== ââ) {
records[id].tracks.push(value);
} else if (value === ââ) {
delete records[id][prop];
} else
console.log(records[id])
return records;
}
This runs perfectly, but if I remove both instances of "console.log(records[id]), it fails.
Itâs very strange - I have reproduced it both in Safari and in Firefox (I know no-one likes using Safari for coding ;))
Here is what is returned in the console if I run the code without the console.logs present: I had to include a screenshot as it would not let me copy/paste the console contents -
I tried to do the homework but am totally baffled by the recursive statements - I have to do my work today then I will be catching up with stream #5 and hopefully it will start to make some sense to me after that
Recursiveness is a tough thing to wrap your head around. In a lot of programming jobs you may not ever need it, but unfortunately it is often a topic during interviews.
This lecture explains it really well Recursion - CS50 Shorts - YouTube (note that the code sample looks like JS but it is C - there is a difference only in how the function definition is done)
Also this video is really good What Is Recursion - In Depth - YouTube . If you are just starting out with JS the last part may be a bit complex to follow, but you can always revisit that later.
And in text, there are quite a few good examples that give you the feel of what recursion is in this post:
Please take note of the joke that Ben Halpern pulled at the top of the post - and see if it makes you smile. If it does, youâve got it!
That is a great find! Very concise! It explains both what is a function (and its input/output) as well as how recursion works. And all in just 6 and a bit minutes! Thanks for sharing!
Hi RamĂłn - Iâm being difficult here. Would it be possible to go over the exercise Profile Lookup at the end of one of the classes please? I have tried it multiple times and although I am getting closer, I donât understand the freecodecamp explanation, and donât just want to copy and paste the solution.
Also, in the exercise Generate Random Whole Numbers in a Range, could you please walk through the code Math.floor(Math.random() * (max - min + 1)) + min. I donât understand the underlying principles here, or the algebra that seems to be involved.
In fact, do you think it would be possible to cover the last exercises in the Basic JavaScript part of the course - up to and including Recursion? Maybe a couple a day after the end of each lesson? Iâm sorry to be demanding, but I am lost with these exercises, and donât find the explanations online very helpful.
Would it be possible to go over the following from Replace Loops using Recursion. I am lost with that stuff, but fine with the ES6 stuff.
Hi Jane, I am sure @hola_soy_milk will respond when he reads your post, but let me attempt to explain your âGenerate Random Whole Numbers in a Rangeâ here:
Remember that Math.random() returns a value between 0 and 1, but can never quite return a 1
The maximum âspanâ for the range of number is determined by the difference between max - min
This âspanâ actually stars from the next number up, and we use floor, which is why we add +1
So for an example where max = 20 and min = 15, this span would yield: 5 + 1
â then multiply this by an outcome of Math.random(), say 0.8 = 4.8
â and take the floor: 4
As we are seeking a value between min and max, we need to increase the value by min (as that was the start value for our range), in this example it would yield 19, a perfectly valid whole number in our 15 to 20 range.
Try to do this exercise also with really small values for theoretical outcome of the random function (like 0.01) and really large (like 0.99) and see if that makes sense now?
See also what happens if you would not add that +1.
Please never feel like youâre being difficult. Learning this stuff is not straightforward at first glance. Having a function call itself is especially weird to wrap around at first.
I canât promise that Iâll be able to do all of these cutting into Q&A, but will find a way to make it work.