Discussion, Questions, and Resources for Part 1 (JavaScript - April 2018 Cohort)

I gotta say, the last few challenges on ES6 have been frustrating… I’m having to look up everything in the forums to figure out how to pass the tests. Higher order arrow functions kicked my butt, and all of the destructuring ones are too. Anyone else having issues or is it all smooth sailing?

I’m stuck on this on - ES6: Use Destructuring Assignment to Pass an Object as a Function’s Parameters

const stats = {
  max: 56.78,
  standard_deviation: 4.34,
  median: 34.54,
  mode: 23.87,
  min: -0.75,
  average: 35.85
};
const half = (function() {
  "use strict"; // do not change this line

  // change code below this line
  return function half(stats) {
    // use function argument destructuring
    return (stats.max + stats.min) / 2.0;
  };
  // change code above this line

})();
console.log(stats); // should be object
console.log(half(stats)); // should be 28.015

I’m lost on this one. the example uses a const set to the parameter, but in this case the parameter is already defined elsewhere.

No, But I have been working with ES6 a lot so destructuring and arrow functions are easier.

You need to destructure min and max in the return function half(stats) line. You can use the information in the Lesson Pane to see how you can destructure a object to use the variables inside the function.

To also give you a better idea. stats.max and stats.min should change. Don’t keep them.

1 Like

they just take practice. at first arrow functions were mind-boggling but now I am annoyed when I have to type the word ‘function’ LOL

1 Like

I put together an explanation that I don’t think gives away the answer.

just hit ‘run’ at the top of the page to see the results for my explanations.
let me know if this is helpful. maybe I’ll turn it into a blog post :smile:

btw, I just realized this will show up inline here in these posts, but it is much easier to follow if you open it in a new tab ans see the code and the results side-by-side

1 Like

thanks guys!! I ended up getting it :slight_smile:

I won’t mention how long it took me to realize what happens when you do this --> (10 - (-2)) instead of (10 + (-2))… :laughing:

question on “create strings using template literals”

on this one the example is not like the challenge, and I’m not sure how to proceed. here’s where I’m at so far:

const result = {
  success: ["max-length", "no-amd", "prefer-arrow-functions"],
  failure: ["no-var", "var-on-top", "linebreak"],
  skipped: ["id-blacklist", "no-dup-keys"]
};
function makeList(arr) {
  "use strict";

  // change code below this line
  const resultDisplayArray =`[ <li class=/"text-warning/">${result.failure[0]}</li>,
   <li class=/"text-warning/">${result.failure[1]}</li>, 
    <li class=/"text-warning/">${result.failure[2]}</li> ]`;
  // change code above this line

  return resultDisplayArray;
}
/**
 * makeList(result.failure) should return:
 * [ <li class="text-warning">no-var</li>,
 *   <li class="text-warning">var-on-top</li>, 
 *   <li class="text-warning">linebreak</li> ]
 **/
const resultDisplayArray = makeList(result.failure);


***challenge***

const result = {
  success: ["max-length", "no-amd", "prefer-arrow-functions"],
  failure: ["no-var", "var-on-top", "linebreak"],
  skipped: ["id-blacklist", "no-dup-keys"]
};
function makeList(arr) {
  "use strict";

  // change code below this line
  const resultDisplayArray = null;
  // change code above this line

  return resultDisplayArray;
}
/**
 * makeList(result.failure) should return:
 * [ <li class="text-warning">no-var</li>,
 *   <li class="text-warning">var-on-top</li>, 
 *   <li class="text-warning">linebreak</li> ]
 **/
const resultDisplayArray = makeList(result.failure);

Found the answer, now I have to figure out how it works!

I’m going to try the ES6 free Udemy course linked at the top, maybe that will help fill in some blanks. There’s a lot of them!

Here is what I came up with. Happy to explain it if you want.

const resultDisplayArray =  arr.map(item=> `<li class="text-warning">${item}</li>`);
1 Like

Thanks, I’d appreciate it! solution was the same as mine, except I used x for item. I think what got me was the map() method - I’m also not super clear on that one.

@nvrqt03 I agree about having blanks after completing the JS curriculum so far. I’m not sure if it’s possible to not have them after using just one curriculum, if that makes sense. There’s so much info and some of it requires one to spend time and energy learning from whatever additional sources one finds useful.

I think the Udemy course looks helpful. Also, I think sharing and explaining/justifying our solutions to some of the more complicated challenges coming up will also be helpful. I’m especially interested in learning best practices in terms of style and algorithm efficiency.

Thanks for sharing! :sunny:

1 Like

I made a video explaining it. It might be a little long-winded but I hope it helps.

4 Likes

btw - thanks for this explanation! it helps to have someone talk it out sometimes.

sometimes, I make videos like this just to make sure I actually understand the concept fully. It’s one thing to go over it in your head, but when you have to speak it out loud as if you are teaching it to someone you quickly find out whether or not you really understand. glad it helped

2 Likes

In ES6 - Use the Rest Operator with Function Parameters, the following paragraph seems to explain the challenge rather than the code right above which has no args array.

The rest operator eliminates the need to check the args array and allows us to apply map(), filter() and reduce() on the parameters array.

This is confusing, anyone agrees?


In ES6 - Use Destructuring Assignment to Assign Variables from Nested Objects, the following paragraph incorrectly implies start is a variable defined in the const expression. In reality, start is the name of the inner object being deconstructed, you can’t use any other variable name there.

In the example above, the variable start is assigned the value of a.start, which is also an object.

It should probably be replaced with:

In the example above, the variable startX is assigned the value of a.start.x, which is also an object.

Please share your thoughts.

Perhaps it would be necessary to introduce these concepts together along with many others, such as “length”, during the basic Javascript curriculum.
There are lots of things like this taken from granted, and for many of us it is the first time with JavaScript. I had little problems with HTML and CSS, but I’m pretty much having to “get a hint” at every point in the JS curriculum, except in the most basic operations.
Part of the difficulty is that we can’t really see what we are doing, unlike in the previous curriculum.

I’ll try to explain myself to the best of my capacity, not being a native English speaker:
In the HTML and CSS curriculum, we could see the results of our coding in the right panel, where the code runs and we see the ninja kitten page. We see the changes in colour, texture, font, etc right besides us. This enables a lot of trial and error, and a lot of code learning and experimentation.

In javascript tutorials, though, it is all very abstract. Many math operations that say us nothing, and little to none experimentation. For example, although I finally begin to use console.log, until very recently I didn’t know how to see the console result of a function being called. Or how it is useful. I still don’t really understand how to correctly code the Records challenge, and I’ve “cheated”: I’ve used the forum to bring the solution, but didn’t really understand what I really did. And I did the basic JS curriculum twice.

It is a very big jump from html-css to JS. I’ve finished the first curriculum in a week, counting the final projects. That was more than a month ago, and since then I’ve been struggling with basic JS. There are a lot of really easy challenges, and between them a lot of very difficult ones that need a giant knowledge leap to resolve. Granted, I’m a working man (a high school teacher), a father of a 4-year old son, and I’m also studying at the University a second career. But none of that really hampered or slowed down my progress in the earlier course. But the basic JavaScript has BSOD me time and again.

The fact is I still see the whole thing as fragmentary and, at best, modular learning. I don’t want to sound ungrateful, but it is a big leap, and there is a lot of challenges that take from granted a lot of knowledge that it was never developed. Some concepts are very easy, and have a lot of covering, and there are some difficultier ones that aren’t really developed at all. Take for example the reduce, filter and map operators, all introduced hastily at a single E6 challenge that was intended to built other knowledge. This was another challenge that I’ve typed from the hint part, in hope of learning what I was doing. Where is the reduce operator used?
I’m not really going to give up, but having to google all of the content do not really helps :confused: .

thanks for sharing.

Sarkari Result Pnr Status 192.168.1.1