hyf-javascript1's People
hyf-javascript1's Issues
hello
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:
-
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.
-
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
-
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. -
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 betweenblowfish
andcapricorn
. In your case it is positioned beforeblowfish
.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 yourconsole.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 thegiraffe
?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
-
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
. Useconst
orlet
instead. -
The code is correct, but please try and avoid single letter variable and parameter names (except for, for instance,
i
in afor
loop). Try to think of names that best describe what the parameter (or function or variable) represents. In this casecolor
would seem an appropriate name. It takes the guessing away for the reviewer reading your code. -
You are calling your function
catFunc()
withmyCat
as parameter, but you are not using themyCat
parameter. If I call your function with some other object, sayhisCat
it will still printmyCat
. 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);
-
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
. -
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");
-
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
===
. -
You have not declared the variable
vehicles
. You should do so withconst
orlet
:const vehicles = ["motorbike", "caravan", "bike", "plane"];
-
Your array is called
vehicles
but here you are trying to access the third element ofvehicle
. Butvehicle
is not an array but a function! Thereforevehicle[2]
prints asundefined
. -
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 acar
, it will still printbike
. -
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 likeresult
orstr
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 servicecars
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. -
Same as above.
-
Correct.
-
You have combined 13 & 14 where they were supposed to be separate, with 14 building on the result of 13.
-
See above.
-
I'm missing your explanation of what is happening here.
-
Same as above
-
Correct.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.