Giter VIP home page Giter VIP logo

hyf-javascript1's People

Contributors

dumie1 avatar

Watchers

 avatar

hyf-javascript1's Issues

Feedback homework week 2

Hi Dumi, here is my feedback on your homework for week 2.

Overall, your code looks good but take special note of item 4 below. Make sure you always ship code that runs.

1. Your repo is missing an .eslintrc file. Because of that you are missing out on the checks that ESLint can do on your code. Please create such a file in the hyf-javascript1 folder and paste in the content as given in the fundamental on Code Formatting.

2. In line 18 of 2-arrays.js, where you are looking for the index of meerkat, it would be better to save that index into a variable. The reason for that is because you are trying delete meerkat from the array in line 19. You should not "hard code" the number 1, but instead use the value you found earlier. Then you can easily deal with the situation of the index of meerkat being changed, e.g. because something was inserted, or that meerkat was deleted by some other code. In the latter case the index would be -1, indicating that nothing was found.

Example:

const meerkatIndex = favoriteAnimals.indexOf("meerkat");
console.log("Item to be deleted is at index: " + meerkatIndex);
if (meerkatIndex !== -1) {
  favoriteAnimals.splice(meerkatIndex, 1);
}
console.log(favoriteAnimals);

3. Looking at your 3-months.js file, which by the way runs correctly, I can see that you still need to update your VSCode settings to enable automatic formatting of your code. Perhaps on your new laptop this hasn't been done yet. Please check the instructions in the VSCode Tips on how to do this.

4. When I run your file 4-maartje.js I get this runtime error:

for (i = 0; i < tasks.length; i++) {
       ^

ReferenceError: i is not defined
    at Object.<anonymous> (/Users/jimcramer/hackyourfuture/class15/js1/dumie/week2_review/4-maartje.js:48:8)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3

I assume your program was running but that you changed something and forgot to try and run it again. Be sure to do a final run of your code before submitting your homework. Please fix this problem.

Why did you include Math.floor() in line 57 of your code?

And, as Husam said, you need to include two decimals for a Euro amount (accurate up to Euro cents).

There is a slight spelling error in Maartje's name: Maatrje -> Maartje. Can't blame you for that. Dutch names are not easy.

Feedback for Week3

Hi Dumie,
Some feedback on your week3 homework.

  • Nice use of comments to give references. Very nice touch
  • 2-more.js: While the result is correct, your function is not pure when it could easily be. You should be returning a string rather than logging it directly. Something like this would be closer to what was asked, and be better style.
function colorCar(color) {
  return 'a ' + color + ' car';
}
console.log(colorCar('red'));
  • 3-more.js: What would happen if I passed an object that looked like this to your function?
const dog = {
  name: 'Holly',
  owner: 'Rohan Nicholls',
  city: 'Amsterdam'
}

You function would break because the fields are hard-coded. With a title like printObject I should be able to pass any object and have the results be correct.
You want to iterate through all the fields and values of the object and print them out. Here is an example of one way to do this (there are many):

function printObject(obj) {
  for (key in obj) {
    console.log(key + ' = ' + obj[key]);
  }
}

This will print out the dog object and the person object with no problem.

  • 4-more.js:
    • Again, you should be returning strings from the function and then printing the return value from the function.
    • Other than that it is correct. However they mention that you should test with more than one value, and as you can see from the 3-more.js this is really important, as it would have uncovered that your function could only print one type of object.
  • 5-more.js: Nice job. The ternary operator is your friend ๐Ÿ˜‰
  • 6-more.js:
    • Nice use of a ternary operator and a variable to handle whether the vehicle is 'new' or 'used'.
    • again, more test cases, you have only tested for an old car, you have not tested for a new car. So you know in the future you should have a test for each branch in your code. So, you would test these inputs at the very least:
vehicleType('red', 1, 1); // => 'a red new car'
vehicleType('blue', 1, 5); // => 'a blue used car'
vehicleType('green', 2, 1); // => 'a green new motorbike'
vehicleType('yellow', 2, 10); // => 'a yellow used motorbike'
vehicleType('magenta', 5, 1); // => 'unknown vehicle'
  • The code works, and the outputs are correct. Well done.
  • 7-more.js:
    • What happens if someone adds a new type to the vehicle array? e.g. 'truck'?
    • Again, it specifically says to return a string, not print directly to console.log.
    • Again too few tests of the code. You should have a test for each type of vehicle, and its color and condition.
    • You have the right idea because you use the array to get the vehicle value, but I would be inclined to save myself a lot of typing by just passing the code directly to the array (maybe with one less). Here is an example:
function vehicleType(color, code, age){
  const vehicle = ['car', 'motorbike', 'caravan', 'bike'];
  const condition = age <= 1 ? ' new ' : ' used ';
  if(code > vehicle.length){
    return 'unknown vehicle'
  } else {
    return 'a ' + color + condition +  vehicle[code - 1];
  }
}
vehicleType('green', 3, 1);
  • 8-more.js:
    • Did you run this code? Because it is not to spec. i.e. you are missing the ' and ' before the last element?
    • in the advertisement function I believe you should be referencing 'vehicleNames' rather than 'category'. 'Category' is not in the function, and is being accessed when it is called because you defined it just before calling the function. This makes your function impure, and will lead to bugs when you you use your code in different contexts.
    • Well done to return a string, and then console.log the returned string from the function call rather than using console.log within the function itself.
    • You really needed to iterate over the array (see code samples above) and when you reached the last element add the ' and ', the value and a '.' to end the sentence.
  • 9-more.js
    • While you adjusted your function to handle the 'scooter' addition. The idea was to add the element and see if they function worked without changing anything else. Refer to my code above for just using a reference to the array index to handle the situation.
  • 10-more.js
    • Looks perfect. Nice job.
  • 11-more.js
    • Again, nice job. Looks perfect.
  • 12-more.js
    • Nice. o3 is a reference to o2. So, the values inside the object are shared between o2 and o3.
  • 13-more.js
    • 42 is not a string datatype, it is a number (an integer specifically).
    • But your second comment is correct and gives the correct answer: typeof returns a string. It does not matter what the first type is, because typeof always returns a string describing the type of the value.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.