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

Omar Qaterge homework week3#98

Closed
omarqaterge wants to merge 2 commits intoHackYourFuture:masterfrom
omarqaterge:master
Closed

Omar Qaterge homework week3#98
omarqaterge wants to merge 2 commits intoHackYourFuture:masterfrom
omarqaterge:master

Conversation

@omarqaterge
Copy link

No description provided.

Copy link

@paulbremer paulbremer left a comment

Choose a reason for hiding this comment

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

Good job Omar! Some small comments and it looks like you forgot task 15?

Task 15: Write some code to test two arrays for equality using == and ===.

Take a look at the code and check if arrays are the same using == and ===. Try console.logging the output; console.log(x == y); // false

@@ -0,0 +1,202 @@
//1

Choose a reason for hiding this comment

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

This is the homework from week2, try to include only the homework for the current week in the pull request. You can make a new branch from master and work from there.

console.log("using splice() a method that changes the contents of an array by removing or replacing existing elements and/or adding new elements)\n \
in .splice(1, 0, 'meerkat') the 1 defines the index that i want to work with and 0 defines the number of elements that i want to replace.\n \
so the value of the array will be:\n \
[\"blowfish\", \"meerkat\", \"capricorn\", \"giraffe\", \"turtle\"]");

Choose a reason for hiding this comment

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

Nice explanation!

console.log("The array has a length of: " + favoriteAnimals.length);
favoriteAnimals.splice(3,1); // delete giraffe from the previous array
console.log(favoriteAnimals);
console.log("The item you are looking for is at index: " + favoriteAnimals.findIndex(animal => animal === "meerkat"));

Choose a reason for hiding this comment

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

This works but a better function is to use the indexOf if you want to search for a simple value, indexOf('meerkat'). You can read more about the differences of findIndex and indexOf here https://stackoverflow.com/questions/41443029/difference-between-indexof-and-findindex-function-of-array

//1
function sum(x, y, z) {
const result = x + y + z;
return result;

Choose a reason for hiding this comment

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

You can even return the statement and don't need to make a const; return x + y + z

//----------------------------------------------------
console.log(vehicle["aircraft"]["id2"]);
//logs helicopter
console.log(vehicle[thirdKey]["id2"]);

Choose a reason for hiding this comment

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

Nice!

}
else if(code === 4){
i = vehicles[3]
}

Choose a reason for hiding this comment

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

This is fine but you can already see that it becomes a bit cumbersome to write almost the same code over and over again. With larger if statements you can look if a loop is better suited for the job.

else {vehicleToService += vehicles[counter] + "s, ";}
}

console.log(" \"Amazing Joe's Garage, we service" , vehicleToService,"\"");

Choose a reason for hiding this comment

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

There is no need for the slashes here console.log("Amazing Joe's Garage, we service" , vehicleToService);, this works fine. You could even use backticks which makes it even easier to work with variables and strings, see https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals

console.log(o3);

//Does the order that you assign (o3 = o2 or o2 = o3) matter?
//yes, because the right side is being assigned to the left side, otherwise it will show that the variable is not defined.

Choose a reason for hiding this comment

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

Yes that is correct. You changed foo on the o2 object, try this exercise again but this time change the whole object so o2 = { foo: "something" }. See if that changes anything.

//13
const person = {htmlCss:"Philipp Beau", cli:"Unmesh Joshi", JavaScript:"Yash Kapila"};


Choose a reason for hiding this comment

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

Did you forgot task 15?

typeof typeof bar;

//typeof bar; returns "number" because a number is assigned to bar as a value
//typeof typeof bar; returns "string" because it is returning the type of "number" which is a string No newline at end of file

Choose a reason for hiding this comment

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

👍

@NoerGitKat NoerGitKat closed this Apr 11, 2019
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.

3 participants