Coder Social home page Coder Social logo

hyf-javascript1's People

Contributors

afra71 avatar

Watchers

 avatar

hyf-javascript1's Issues

Feedback homework week 3

Hi Afra, here is my feedback on your JS1 week 3 homework.

There are a couple of things that you need to look at:

  1. When an assignment says that your function should produce some output when called with a specific set of parameters, you should not assume that this function will always be called with that same set of parameters. You should also produce something sensible when other values are used.

  2. There are some hints in your code that suggest to me that perhaps you still need to add some settings to your VSCode editor, specifically having to do with code formatting. Please check the VSCode Tips again and make sure the recommended settings are applied.

Step 4: Strings and Array challenges

  1. Excellent that you used the .replace() method in combination with a regular expression. We won't cover regular expressions in the lectures as it is an advanced, vast topic but at least you got a taste of it here.

  2. You added turtle to the array with .unshift(), which inserts the element at the beginning of the array. While the assignment isn't explicit how the new element should be added, it is customary to add it at the end of the array if no explicit order is specified. It is also slightly more efficient, especially with large arrays, as the existing elements do not have to be bumped one position to the right.

    The assignment specifies that meerkat should be placed between blowfish and capricorn. In your case it is positioned before blowfish.

    Do not use the array constructor function (i.e., Array()) to construct a new array. The only thing this function does when used in this way is to create an array without any elements and sets its .length property to the value that you passed as a parameter. It does not actually create any elements! Apart from that, since you set the .length to 4 that becomes the actual length, and not 5 as your console.log says.

    Anyway, we were interested in the length of your favoriteAnimals array, not of some new array.

    If you added the turtle at the end of the array then your .pop() could not be used. You would need another array method to do that. Can you change your .unshift() into a .push() and then find out how to get rid of the giraffe?

    In line 25, again, don't use the Array() constructor function. Always use a simple array literal in these cases (it even saves you some typing):

    const ar = ['blowfish', 'capricorn', 'giraffe'];

    But what is the purpose of this ar array anyway? You declare it here but it remains unused.

    You should try and be consistent how you use quotes to enclose string literals in your code. Either choose single or double quotes and then stick to your choice throughout your code.

More JavaScript

  1. While I think you grasped the concept of a function taking arguments and returning a value, the result is not the asked for sum of the arguments, but something else. I couldn't blindly take your function and trust it to produce the sum of its three arguments.

    Don't use var. Use const or let instead.

  2. The code is correct, but please try and avoid single letter variable and parameter names (except for, for instance, i in a for loop). Try to think of names that best describe what the parameter (or function or variable) represents. In this case color would seem an appropriate name. It takes the guessing away for the reviewer reading your code.

  3. You are calling your function catFunc() with myCat as parameter, but you are not using the myCat parameter. If I call your function with some other object, say hisCat it will still print myCat. Try this instead:

    let myCat = {
      name: "leo",
      age: 3,
      color: "orange"
    };
    
    let hisCat = {
      name: "binky",
      age: 2,
      color: "black"
    }
    
    function catFunc(someCat) {
      console.log(someCat);
    }
    
    catFunc(myCat);
    catFunc(hisCat);
  4. Always use the triple equal === or, for unequal !==.

    What happens if I call your function with a code of 1? The assignment says it should print something about a car.

  5. Don't use the ternary operator like you did here. See The conditional (ternary) operator in the fundamentals. Preferred:

    console.log(3 === 3? "yes" : "no");
  6. Your function is never called. This is because you have defined another function with the same name vehicle in line 92 which overrides the one you have defined here. So, line 82 actually calls the function from line 92, which doesn't produce any output when called with a code equal to 1.

    Remember to use ===.

  7. You have not declared the variable vehicles. You should do so with const or let:

    const vehicles = ["motorbike", "caravan", "bike", "plane"];
  8. Your array is called vehicles but here you are trying to access the third element of vehicle. But vehicle is not an array but a function! Therefore vehicle[2] prints as undefined.

  9. In this function you do not use the code parameter. This means that if I call your function with a different code, say 1 for a car, it will still print bike.

  10. When you concatenate strings we do not call the result a sum. We only do that for numbers. In this case you could use a name like result or str or something like that.

    You should only use the vehicle names that are in the array and not always add ' and cars' to the end of the string. Perhaps Joe's Garage will not want to service cars in the future and expects that changing the array is sufficient to do that.

    There should be a period . at the end of the sentence.

  11. Same as above.

  12. Correct.

  13. You have combined 13 & 14 where they were supposed to be separate, with 14 building on the result of 13.

  14. See above.

  15. I'm missing your explanation of what is happening here.

  16. Same as above

  17. Correct.

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.