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

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

yeah that’s what’s tough - its kind of inconsistent.

0 Likes

#39

There aren’t any. In some languages, constants are capitalised (generally by convention). When you see someone capitalising, it’s likely they’ve come from a language like C/C++/Ruby/similar

Const-correctness is an issue in imperative languages like C++ because by default name bindings typically create variables, which can vary, as the name suggests, and thus if one wishes to mark a binding as constant this requires some additional indication.

…hence CONSTS_ARE_WRITTEN_LIKE_SO so that you can see they’re a constant.

consts in JS generally are not capitalised: it doesn’t matter in JS, which works differently to C/C++/etc. You can use consts everywhere, they aren’t special, so it doesn’t really make sense to capitalise them unless you really like having AN_EXTREMELY_SHOUTY_PROGRAM, which is just going to annoy people reading your code

note classes are title cased, and that’s just convention as well, but that one you do need to stick to because it’s extremely confusing to anyone reading your code if there are Identifiers That Are TitleCased That Are Not Used For Classes.

1 Like

#40

@nvrqt03 There are a couple of relatively well-known style guides you may want to use for your projects, or base your own style guides on for capitalization and other code styles:

  • Google JavaScript Style Guide

    Constant names use CONSTANT_CASE: all uppercase letters, with words separated by underscores. There is no reason for a constant to be named with a trailing underscore, since private static properties can be replaced by (implicitly private) module locals.

  • Airbnb JavaScript Style Guide

    23.10 You may optionally uppercase a constant only if it (1) is exported, (2) is a const (it can not be reassigned), and (3) the programmer can trust it (and its nested properties) to never change.

Both guides go into more detail about when and when not to capitalize, with examples.

1 Like

#41

good find, thank you!!

0 Likes

#42

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?

0 Likes

#43

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.

0 Likes

#44

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

0 Likes

#45

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

#46

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

#47

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

#48

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:

0 Likes

#49

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);

0 Likes

#50

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!

0 Likes

#51

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

#52

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.

0 Likes

#54

@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

#55

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

4 Likes

#56

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

0 Likes

#57

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

#59

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.

0 Likes