lab-brussels-1 / home

Home repository for Lab Brussels 1.
https://lab-brussels-1.github.io/home
MIT License
4 stars 5 forks source link

Cristobal: Behaviour Strategy Implementation, 3 weeks #348

Open alexander-lopez-s opened 2 years ago

alexander-lopez-s commented 2 years ago

Learning Objectives

Priorities: πŸ₯š, 🐣, πŸ₯, πŸ” (click to learn more)
There is a lot to learn in this repository. If you can't master all the material at once, that's expected! Anything you don't master now will always be waiting for you to review when you need it. These 4 emoji's will help you prioritize your study time and to measure your progress: - πŸ₯š: Understanding this material is required, it covers the base skills you'll need to move on. You do not need to finish all of them but should feel comfortable that you could with enough time. - 🐣: You have started all of these exercises and feel you could complete them all if you just had more time. It may not be easy for you but with effort you can make it through. - πŸ₯: You have studied the examples and started some exercises if you had time. You should have a big-picture understanding of these concepts/skills, but may not be confident completing the exercises. - πŸ”: These concepts or skills are not necessary but are related to this module. If you are finished with πŸ₯š, 🐣 and πŸ₯ you can use the πŸ” exercises to push yourself without getting distracted from the module's main objectives. ---

1. Remix

Practice studying and remixing other people's solutions to coding challenges. Create your own solutions by mixing and matching pieces from other people's code.

2. Write

3. Review


alexander-lopez-s commented 2 years ago

Week 1

I Need Help With:

What went well?

What went less well?

Lessons Learned

Sunday Prep Work

danielhalasz commented 2 years ago

I am not confident with the throwError() function, I will research on the internet for more information.

Evan will add some examples with throwing errors next week, in the meantime you can also try changing the functions to return a certain output instead..and then expect that output in the test.

I am not clear why do we need Sandbox or any other testing platforms. Are they pre-created libraries?

testing is not built into JS, and there are different tools to do unit-testing. One of the most popular ones is maintained by Facebook and is called Jest. In the repo, we use Jest for testing. So you can check out the Jest documentation to read more about it.

alexander-lopez-s commented 2 years ago

Week 2

I Need Help With:

What went well?

What went less well?

Lessons Learned

Sunday Prep Work

danielhalasz commented 2 years ago
  • I still have problems understanding the use of arguments and parameters. Why do we sometimes leave the parenthesis empty function speed (){ and sometimes we declare variables inside? function speed (distance, time){?

well depends what the function is doing..does it take any input values or not? for example, we could have:

const myFunction1 = () => {
  console.log('hello Cris');
}

const myFunction2 = (name) => {
   console.log('hello' + name);
}

now, if you call the first function, it will always console.log hello Cris but the second one will say hello "name"

myFunction1();
myFunction1('Dorian');
myFunction2('Dorian');
myFunction2('Cris');
danielhalasz commented 2 years ago
  • What is the difference between console.log(); and return();?

I assume you mean executing something like console.log(123) and writing inside a return statement inside a function like:

const myFunction3 = () => {
    return 123;
}

now, console will print 123 to the console...while return will pass on the number 123 to whatever is calling myFunction3.. let's say:

const myFunction3 = () => {
    return 123;
};

console.log(myFunction3());
danielhalasz commented 2 years ago
  • I understand the difference between toBe and equalTo. toBe uses strict equality, toEqual uses property equivalence. expect(0).toBe(-0) will pass but expect(0).toEqual(-0) will fail.

you seem to understand it..but toBe is NOT strict equality..toEqual is πŸ™‚

danielhalasz commented 2 years ago
  • I tend to create a function first and then, to write the tests. I know this is not a good practice but it becomes challenging for me referencing to something I do not see.

the goal is not to have an implementation..with the TDD approach..the goal is to make sure that certain input scenarios will have a certain outcome.. so you just want to write down.. giving an input string should pass a number array should fail..or something like that..HOW that happens..can be dealt with later..

danielhalasz commented 2 years ago
  • There are multiple testing frameworks likeΒ Jest,Β Jasmine,Β Mocha, we can use whatever we want, but we need to install the dependencies first.

yes, although Jest is already a dependency in the HYF repo, so enough to do npm i

danielhalasz commented 2 years ago
  • I am not good at debugging with VS code, have practiced but it is confusing. There is too much ongoing at the same time. I will try practicing with VS with a very basic exercise.

it is basically the same as Chrome Dev Tools, just a slightly different interface, so can be confusing at first :) in VSCode..you won't be able to debug stuff that involves the DOM, of course..

alexander-lopez-s commented 1 year ago
const myFunction3 = () => {
    return 123;
}

So, return will work inside the function while console.log will show the returned result in the console!

alexander-lopez-s commented 1 year ago

It's clear as water!!!! Thanks for these examples.

alexander-lopez-s commented 1 year ago

Week 3

I Need Help With:

// voltage = current * resistance
function calculateVoltage (){
    let current = document.getElementById("current").value;
    let resistance = document.getElementById("resistance").value;
    let voltage = 0;`
if (current =< 10 && ....... 

What went well?

What went less well?

Lessons Learned

describe('sortNumbers sorts an array of numbers', () => {
  describe('sorts positive numbers', () => {
    it('whole numbers', () => {
      const expected = [0, 1, 2, 3, 5];
      const received = sortingNumbers([5, 2, 0, 3, 1]);
      expect(received).toEqual(expected);

Sunday Prep Work

danielhalasz commented 1 year ago
  • What is the rule for declaring variables outside the scope? Do we always need to do that?

There is no rule, it depends on what you want to achieve, if you want to use it outside of the scope or not.

  • Why do we need to install canvas? npm i canvas

you do not need to install canvas manually like this.. it is just a peer-dependency for one of the npm packages, that gets installed for some HYF repos.

  • Is it always a good practice to keep our arrays untouched? Like, making a copy of the original one and saving it in a variable?

again, depends on your goal..but in general yes, it can be a good practice to do that.

  • How can we test functions when we are getting the values from the user directly?

this is a really good question. well, we can create test cases for all possible scenarios that could end up in to input field..and the are also tools to help with stubbing&mocking data. this is beyond the scope of what we are doing now, but you can look into it, if you are interested.

  • Is is optional to declare parameters?

sure, absolutely. it depends on what the function is doing, if it accepts any input parameters..

  • I also practiced shorting an array with the .length = 0 function.

why would you do this?

  • I created for my very first time an arrow function and it is working perfectly (though I am not a fan of those at all).

great job! try to get used to them, as that is the current standard :)

  • Long functions are difficult to read, I need a lot of comments to understand what is going on.

indeed, writing good documentation is very important and often overlooked

  • Still I do not know how many type of cases do we have, like in this week exercises I saw a test with variables.

can you pls rephrase this question? I am not sure I understand it.