dumie1 / hyf-javascript1 Goto Github PK
View Code? Open in Web Editor NEWHomework Javascript 1
Homework Javascript 1
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.
Hi Dumie,
Some feedback on your week3 homework.
function colorCar(color) {
return 'a ' + color + ' car';
}
console.log(colorCar('red'));
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.
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'
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);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.