Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Abdullah Al Ahmad #114

Closed
wants to merge 3 commits into from
Closed

Conversation

AbduCodecamp
Copy link

JavaScript homework - week1

JavaScript homework - week1
Copy link
Contributor

@marcianoviereck marcianoviereck left a 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.


var x;

console.log("the value of my variable x will be: a number");
Copy link
Contributor

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?


x = 12;

console.log("the value of my variable x will be: a number");
Copy link
Contributor

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?


var y = 'Tom';

console.log("the value of my atring y will be: a name");
Copy link
Contributor

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


var round = Math.round;

var a = round(z);
Copy link
Contributor

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);


// Variables & Values

var x;
Copy link
Contributor

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


if (a<z) {
var i = z;
console.log(i);
Copy link
Contributor

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);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or with Math.max


var myFavoriteAnimals;

console.log('The value of heros is: animales\'s names');
Copy link
Contributor

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


console.log(myFavoriteAnimals);

myFavoriteAnimals = myFavoriteAnimals + [', baby pig'];
Copy link
Contributor

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:)

@@ -0,0 +1,175 @@
// Greetings
Copy link
Contributor

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.

@wouterkleijn
Copy link
Contributor

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!

Copy link
Contributor

@marcianoviereck marcianoviereck left a 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'];
Copy link
Contributor

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.

Copy link
Contributor

@marcianoviereck marcianoviereck left a 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)
}
Copy link
Contributor

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++){
Copy link
Contributor

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

Copy link
Contributor

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){
Copy link
Contributor

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) {
Copy link
Contributor

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>`
Copy link
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants