Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
100 changes: 99 additions & 1 deletion 1. objects/1.md
Original file line number Diff line number Diff line change
@@ -1,73 +1,142 @@
1. Pick a penguin from Wikipedia's List of Fictional Penguins (https://en.wikipedia.org/wiki/List_of_fictional_penguins) and create an object named `myPenguin` with properties that represent the information listed in each column on that Wikipedia page (for example: the character's name, origin, and author).
1. Pick a penguin from Wikipedia's List of Fictional Penguins (https://en.wikipedia.org/wiki/List_of_fictional_penguins) and create an object named `myPenguin` with properties that represent the information listed in each column on that Wikipedia page (for example: the character's name, origin, and author).

```js
// your code goes here

var myPenguin = {
name : "Patrick",
canFly : false,
hello : function sayHello(){
return (`Hello, I'm a penguin and my name is ${myPenguin.penguin.name}!`);
},
chirp : function chrip(){
return "CHIRP CHIRP! Is this what penguins sound like?";
},
fly : function fly(){
if (canFly == true) {
consloe.log("I can fly!");
} else {
console.log("No flying for me!");
}
},
1 : { "Literature":
{
1.1 : "comics"
}
},
2 : "Theatre",
3 : {"in media":
{
3.1 : "Animations",
3.2 : "video games",
3.3 : " Other media (toys, mascots, logos, etc.)"
}
},
4 : "See also",
5 : "References",
};
for(let key in myPenguin){
console.log(Object.keys(myPenguin.penguin);
}




```

2. Use console.log() to print the penguin's name to the console as part of a welcome message, like "Hello, I'm a penguin and my name is [NAME HERE]!"

```js
// your code goes here
console.log(`Hello, I'm a penguin and my name is ${myPenguin.name}!`)
```

3. Write another line of code that adds a new property to your penguin called canFly and set it to false.

```js
// your code goes here
canFly : false
console.log(myPenguin["penguin"]["canFly"])
```

4. Add a method to your penguin called chirp that prints to the console: "CHIRP CHIRP! Is this what penguins sound like?"

```js
// your code goes here
chirp : chrip(){
return "CHIRP CHIRP! Is this what penguins sound like?"
}
console.log(myPenguin.penguin.chrip)
```

6. Next, call your penguin's sayHello() method and make sure that it works!

```js
// your code goes here
hello : sayHello(){
return `Hello, I'm a penguin and my name is ${this.name}!`
},
```

7. Without modifying any of your previous code, change the penguin's name to "Penguin McPenguinFace" and then call your penguin's sayHello() function one more time to make sure it still works.

```js
// your code goes here
myPenguin["penguin"]["name" = "Penguin McPenguinFace"]
```

8. Write another method called fly, and inside that method, use an if / else statement to print "I can fly!" to the console if your penguin's canFly property is true, or "No flying for me!" if its canFly property is false.

```js
// your code goes here
fly : function fly(){
if (canFly == true) {
consloe.log("I can fly!");
} else {
console.log("No flying for me!");
}
}

```

9. Call your penguin's fly() method and make sure it works!

```js
// your code goes here
myPenguin["penguin"]["fly"]
```

10. Change the canFly property to true -- again, without modifying any of your previous code!

```js
// your code goes here
myPenguin["penguin"]["canFly" = true ]
```

11. Now call your penguin's fly() method again and make sure it works as expected!

```js
// your code goes here
myPenguin["penguin"]["fly"]
```

12. Write a for ... in loop to print each key to the console. (Hint: See this page for an example of this special type of loop.)

```js
// your code goes here
for(let key in myPenguin){
console.log(key);
}
```

13. Write another for ... in loop to print the value of each key to the console. (Hint: You'll need to use bracket notation to access the values this way, instead of dot notation!)

```js
// your code goes here
for(let key in myPenguin){
console.log(myPenguin.key);

}
```

## Exercise 2
Expand All @@ -84,6 +153,13 @@

```js
// your code goes here
let favouriteRecepie = {
title: Mole,
serves: 2,
ingrediants: ["cinnamon","cumin","cocoa"]
}


```

15. Keep track of which books you read and which books you want to read!
Expand All @@ -94,4 +170,26 @@

```js
// your code goes here
let books = [
{
title : "Eclipse",
author : "Stephenie Meyer",
alreadyRead : true,
},
{
title : "Harry Potter",
author : "J.K Rowling",
alreadyRead : false,
}
];

for (let book in books) {
console.log(`${books[book]["title"]} by ${books[book]["author"]}`);
if (books[book]["alreadyRead"]) {
console.log(`You already read ${books[book]["title"]} by ${books[book]["author"]}`);
}
else {
console.log(`You still need to read ${books[book]["title"]} by ${books[book]["author"]}`);
}
}
```
43 changes: 38 additions & 5 deletions 1. objects/2.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,56 @@
// Using the different way of accessing and assigning a value to the object using `.` or `[]`

var obj = {
name:"sunny",
age:21,
qualification:"B.tech"
}
console.log(obj.name);
console.log(obj["age"]);
// 1. Define a variable named `user` and assign a blank object to it.
var user = {};

// 2. Add a key of `user name` and a value of `Black Panther` to that object.
var user = {
userName:"Black Panther",
10:batch,
42:`The answer to the meaning of life 🧸`
}

// 3. Using `console.log` log the value of `user name` key from the user object.

console.log(user.userName);
// 4. Add a key of the value of variable `batch` in the object with the value of 10.
var batch = "myBatch";
var user = {
userName:"Black Panther",
10:batch,
42:`The answer to the meaning of life 🧸`
}

// 5. Using the alert function alert the value of the key added above.
alert(user[10]);

// 6. Add a key of `42` to the object with a value of `The answer to the meaning of life 🧸`.

var batch = "myBatch";
var user = {
userName:"Black Panther",
10:batch,
42:`The answer to the meaning of life 🧸`
}
// 7. Using the function console.log log the value of the key `42`.

console.log(user[42]);
// 8. Add a key in your object with the value of the variable `city`. The value of the key should be `true`.
var city = prompt("Enter the city name you visited las time.");
var batch = "myBatch";
var user = {
userName:"Black Panther",
10:batch,
42:`The answer to the meaning of life 🧸`,
true:city,
let :"you",
var :"me"
}

// 9. Uisng console.log log the value of the key defined above.

console.log(user[true])
// 10. Can you define a key of `let or var` in any object? Reason.
yes we can take var or let as key because objects just understand key value pairs. but it will target all var inside the obj.
27 changes: 27 additions & 0 deletions 2. array/1.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,97 @@

```js
// your code goes here
let colors =["red","blue","green","cyan","magenta"]
```

2. Access the first color in the array and print it to the console using console.log()

```js
// your code goes here
console.log(colors[0])
```

3.Now do the same with the third color in the list. (Remember that array indexes start at 0, not at 1!)

```js
// your code goes here
console.log(colors[2])
```

4.Write one line of code that changes the value of the last color in the list to "ultraviolet" (overwriting the previous value).

```js
// your code goes here
colors[4] = "ultraviolet"
console.log(colors[4])
```

5. Create a new variable called fourthColor and set it equal to the fourth color in the list.

```js
// your code goes here
let fourthColor = colors[3];
console.log(forthColor);
```

6.Add another color to the end of the list.

```js
// your code goes here
colors.push("green")
console.log(colors)
```

7.Add another color to the beginning of the list.

```js
// your code goes here
colors.unshift("black")
console.log(colors)
```

8. Print the length of the array to the console with console.log()

```js
// your code goes here
console.log(colors.length)
```

9.Remove the last color from the end of list, and then print the length of the array to the console one more time.

```js
// your code goes here
colors.pop()
console.log(colors)
```

10.Write a for loop to iterate through every color in the array and print each color's value to the console.

```js
// your code goes here
for (let values in colors){
console.log(colors[values])
}
```

11.Copying from that loop you just wrote, modify it to print every color's value and every color's index in this format: 3, purple or 0, blue etc.

```js
// your code goes here
for (values = 0; values < colors.length ; values++){
console.log(`the index of ${colors[values]}, is ${[values]}`);
}
OR //
for (let values in colors){
console.log(`the index of ${colors[values]}, is ${values}`);
}
```

12.Create a variable named lastColor that will always point to the last element of the colors array, no matter how many colors are in the list. (Hint: make use of the array's length property for this!)

```js
// your code goes here
let lastColor = colors.(length-1);


```
Loading