const colorsArray = ["yellow", "red", "turquoise", "green", "blue"]
const myDog = {
name: "Clyde",
breed: "boxer",
age: 3,
}
-
create an object called anotherDog with the properties name, breed and age (you can choose the values for these properties)
-
add the information gender:female to myDog
-
add the information gender:male to anotherDog using a different method to the one you used for question 2.
-
change the age of myDog from 3 to 7
-
create a method on the myDog object called 'playFetch' that, when called console.logs 'i am playing fetch'
-
create a method on myDog called "myName" that uses the 'this' keyword so that when called it console.logs 'my name is Clyde' . Note the name should be inserted dynamically such that if we changed the name the function would reflect the change.
-
delete the property 'breed' from anotherDog
-
create a function called hasBreed that takes an object and checks if it has the property 'breed'. hasBreed(myDog) should return true, hasBreed(anotherDog) should return false.
-
calculate how many key value pairs myDog contains
-
create a copy of myDog object so that if you change the name of the copy it does not change the name of the original.
arrays
use the filter method to create an array with all colors from colorsArray that are longer than 5 letters long. expected answer is [ 'yellow', 'turquoise']
a) use the forEach method to create an array that has each color from colorsArray in capital letters. expected answer is [ 'YELLOW', 'RED', 'TURQUOISE', 'GREEN', 'BLUE' ]
b) create the same array using the map method
use the reduce method to find the color with the most amount of letters in colorsArray.
expected answer is 'turquoise' (as a string, not in an array)
objects
create an object called anotherDog with the properties name, breed and age (you can choose the values for these properties)
add the information gender:female to myDog
add the information gender:male to anotherDog using a different method to the one you used for question 2.
change the age of myDog from 3 to 7
create a method on the myDog object called 'playFetch' that, when called console.logs 'i am playing fetch'
create a method on myDog called "myName" that uses the 'this' keyword so that when called it console.logs 'my name is Clyde' . Note the name should be inserted dynamically such that if we changed the name the function would reflect the change.
delete the property 'breed' from anotherDog
create a function called hasBreed that takes an object and checks if it has the property 'breed'. hasBreed(myDog) should return true, hasBreed(anotherDog) should return false.
calculate how many key value pairs myDog contains
create a copy of myDog object so that if you change the name of the copy it does not change the name of the original.