-
Notifications
You must be signed in to change notification settings - Fork 256
Conversation
JavaScript homework - week1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the homework looks fine.
Try to avoid using var
, but use let
or const
instead. And also split up the homework in separate files.
Week1/js1-w1-A.A.A.js
Outdated
|
||
var x; | ||
|
||
console.log("the value of my variable x will be: a number"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the value of x
will be a number
, are you sure this is correct?
Week1/js1-w1-A.A.A.js
Outdated
|
||
x = 12; | ||
|
||
console.log("the value of my variable x will be: a number"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the value of x
will be a number
, are you sure this is correct?
Week1/js1-w1-A.A.A.js
Outdated
|
||
var y = 'Tom'; | ||
|
||
console.log("the value of my atring y will be: a name"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here the same:) as above
Week1/js1-w1-A.A.A.js
Outdated
|
||
var round = Math.round; | ||
|
||
var a = round(z); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, you can also do this in one line, like this:
const a = Math.round(z);
Week1/js1-w1-A.A.A.js
Outdated
|
||
// Variables & Values | ||
|
||
var x; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use var
please, use let
or const
Week1/js1-w1-A.A.A.js
Outdated
|
||
if (a<z) { | ||
var i = z; | ||
console.log(i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can also do this directly:
if (a<z) {
console.log(z);
} else {
console.log(a);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or with Math.max
Week1/js1-w1-A.A.A.js
Outdated
|
||
var myFavoriteAnimals; | ||
|
||
console.log('The value of heros is: animales\'s names'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is correct, heros
is not the name of the variable and the value is incorrect
Week1/js1-w1-A.A.A.js
Outdated
|
||
console.log(myFavoriteAnimals); | ||
|
||
myFavoriteAnimals = myFavoriteAnimals + [', baby pig']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A cleaner (and better) solution is:
myFavoriteAnimals.push('baby pig');
I think this works better:)
Week1/js1-w1-A.A.A.js
Outdated
@@ -0,0 +1,175 @@ | |||
// Greetings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you split your homework up in different files? As requested in the assignment:
For all the following exercises create a new .js file. Try to find a proper name for each file or make a small comment about what it does inside for future reference.
Thanks @AbduCodecamp for addressing some of Marciano's feedback. Next time also place some comments directly answering his concerns if possible. @marcianoviereck Can you have a final look? Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, I just have one last minor comment, if that is fixed then the homework of week 2 is approved. I will still check the week 3 homework
|
||
console.log(myFavoriteAnimals); | ||
|
||
myFavoriteAnimals = myFavoriteAnimals + [', baby pig']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to use myFavoriteAnimals.push('baby pig')'
. This will work but it's not the correct way to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Homework for week 2 is approved, but for week 3 I have some remarks. And I think that you forgot some parts of the homework (see my other comments)
else { ad += vehicles[i]+ 's' + ', ' ; | ||
} | ||
}console.log(ad) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine, it would be more readable if you add more spaces and align your brackets ({
), like this:
And I would advise to put the code of 's' + ' and '
not in that part, but always add the s
in the other if statement. It's difficult to explain so here is the code of what I mean:
let ad = "Amazing Joe's Garage, we service ";
function advertisement (){
for( i = 0 ; i < vehicles.length; i++){
if (i == vehicles.length-1) {
ad += ' and ' + vehicles[i] + 's' + '.';
} else if(i == vehicles.length-2) {
ad += vehicles[i]; + 's'
} else {
ad += vehicles[i]+ 's' + ', ' ;
}
}
console.log(ad);
}
|
||
function sum(){ | ||
let sum =0; | ||
for(let i=0;i<arguments.length;i++){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
technically this is correct, but I think that the assignment meant that you explicitly define three arguments and combine those. but I guess you know how to do that, since you've done it in a more complex way. So it's okay
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A tip: This is a pretty clever solution actually. But more difficult in use for other programmers if you collaborate on the code, because it is not intuitive for someone to know how many arguments they have to pass to the function and what will happen to them. So this is just a tip for the future, this solution is clever but not really good if you are collaborating with other programmers.
@@ -0,0 +1,18 @@ | |||
// Create a function called vehicle, like before, but takes another parameter called age, so that vehicle("blue", 1, 5) prints 'a blue used car' | |||
|
|||
function vehicleType(color,code, age){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also correct, but it's not a good practice to modify the arguments that are passed in the function. Because if you modify a property of that argument in the function, it will also change the property for that argument outside the function. I know this is not the case in this specific function, but it could happen in the future, which could lead to confusing results. For example:
function vehicleType(color,code, anObject){
if (anObject.age < 1) {
anObject.age = 'bused'
} else {
anObject.age = ' new'
}
if (code == 1){
console.log('a ' + color + anObject.age + ' car');
} else if (code == 2) {
console.log('a ' + color + anObject.age + ' motorbike');
}
}
let color = "green";
let code = 1;
let anObject = { age: 12, name: "test" };
console.log("before the function, the age is " + anObject.age);
vehicleType(color, code, anObject);
console.log("after the first function, the age is " + anObject.age);
In this code example, the property age
is modified in the function, which affects the anObject
variable, which is outside the function.
let vehicles = [' car', ' motorbike', ' bike', ' caraven' ]; | ||
|
||
function vehicleType(color,code, age){ | ||
if (age < 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here the same remark as above (about the bad practice to modify an argument that is passed in the function)
|
||
<h1 style="color: red; font: 3em sans-serif;">JS-week3</h1> | ||
|
||
<script src="strings.js"></script>` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you forgot some parts of the homework?
I think assignment 12 untill 16 are missing, see the homework
JavaScript homework - week1