├── README.md └── slides.pdf /README.md: -------------------------------------------------------------------------------- 1 | # JavaScript Full Course 2023 2 | 3 | - [JavaScript Video](https://youtu.be/lGmRnu--iU8) 4 | 5 | - [Course Notes Slide PDF](slides.pdf) 6 | 7 | - [Advanced JavaScript Video](https://www.youtube.com/watch?v=gUUCmRJjVvo) 8 | - [Advanced JavaScript Notes](https://coderdost.github.io/) 9 | 10 | ### Note: More questions to be updated in 24 Hours. 11 | 12 | ## Chapter 1 (Data Types) 13 | 14 | ### Assignments 15 | 16 | **1.1:** Create a code to check difference between `null` and `undefined` data type. Also check their type using `typeof`. 17 | 18 | **1.2:** Which type of variables (var, let or const) must be **initialized** at the time of declaration? 19 | 20 | **1.3:** Guess the **Output** and Explain Why? 21 | 22 | _[From video lecture 1.5]_ 23 | 24 | ```js 25 | let languages = 'java javaScript python cSharp'; 26 | 27 | let result = languages.lastIndexOf('S'); 28 | 29 | console.log(result); 30 | ``` 31 | 32 | **1.4:** Guess the **Output** and Explain Why? 33 | 34 | _[From video lecture 1.8]_ 35 | 36 | ```js 37 | let variable = 'hello programmers'; 38 | 39 | let result = Number(variable); 40 | 41 | console.log(result); 42 | ``` 43 | 44 | **1.5:** Guess the **Output** and Explain Why? 45 | 46 | ```js 47 | let num1 = 32; 48 | 49 | let num2 = '32'; 50 | 51 | let result1 = num1 !== num2; 52 | 53 | let result2 = num1 != num2; 54 | 55 | console.log(result1, result2); 56 | ``` 57 | 58 | **1.6:** Guess the **Output** and explain Why? 59 | 60 | ```js 61 | let str = 'Hello Programmers'; 62 | 63 | let result = str.includes('r'); 64 | 65 | console.log(result); 66 | ``` 67 | 68 | **1.7:** Guess the **Output** and Explain Why? 69 | 70 | _[From video lecture 1.6]_ 71 | 72 | ```js 73 | let num1 = 2; 74 | 75 | let num2 = 5; 76 | 77 | let result = num1 ** num2 * 2; 78 | 79 | console.log(result); 80 | ``` 81 | 82 | **1.8:** Guess the **Output** and Explain Why? 83 | 84 | ```js 85 | let num1 = [1, 2, 4, 5]; 86 | 87 | let num2 = [6, 5, 8, 0]; 88 | 89 | let result = num1.concat(num2); 90 | 91 | console.log(result); 92 | ``` 93 | 94 | **1.9:** Guess the **Output** and Explain Why? 95 | 96 | ```js 97 | let a = 5; 98 | 99 | let b = 7; 100 | 101 | let c = 8; 102 | 103 | let result = a < b > c; 104 | 105 | console.log(result); 106 | ``` 107 | 108 | **1.10:** If your State is split into **four** equal parts such that in each part there are **1/4** number of people live. You have to find how many people would live in each part? which operators will you use ? 109 | 110 | _[From video lecture 1.6]_ 111 | 112 | ## Chapter 2 (Control Flow / Conditional) 113 | 114 | ### Assignments: 115 | 116 | **2.1:** Guess the **Output** And Explain Why? 117 | 118 | ```js 119 | let i = 4; 120 | 121 | for (let j = 0; i < 10; i++) { 122 | if (j === 1 || i === 6) { 123 | continue; 124 | } else { 125 | console.log(i, j); 126 | 127 | if (i === 7) { 128 | break; 129 | } 130 | } 131 | } 132 | ``` 133 | 134 | **2.2:** Guess the **Output** and Explain Why? 135 | 136 | ```js 137 | let i = 0; 138 | 139 | for (i; i < 5; i++) { 140 | console.log(i); 141 | } 142 | ``` 143 | 144 | **2.3:** Write a simple **Program** in which You have to print first **10** numbers in **descending** order (10...1)? 145 | 146 | **2.4:** Lets say `John` is looking a new `country` to live in. He want to live in a country that speaks `English`, has less than 10 million people. One of the `food` option between these two must present `Spanish food` OR `English food`. 147 | 148 | **Write** an if/else if statement to help john figure out Your country is right for him? 149 | 150 | _[From video lecture 2.4]_ 151 | 152 | **2.5:** Guess the **Output** And Explain Why? 153 | 154 | ```js 155 | for (let i = 0; i < 10; i++) { 156 | console.log(i); 157 | } 158 | 159 | console.log(i); 160 | ``` 161 | 162 | **2.6:** use **nested-if** statement to check your `age>18` 163 | 164 | than check your height `height > 5.10`. 165 | 166 | If **both** true show any message(**I can sit in exam**) in the console? 167 | 168 | **2.7:** Create two variables `grade` and `passingYear`.Check if your `grade == "A"` and `passingYear < 2020` with the help of **ternary** operator(Not allowed to use any logical operator).If both condition `true` print on console **Qualify**. Otherwise **Fail** 169 | 170 | _[From video lecture 2.9]_ 171 | 172 | ## Chapter 3 (Functions) 173 | 174 | ### Assignments 175 | 176 | **3.1:** Create a **function Declaration** called `describeYourState` Which take three parameters `Population`, `traditional food` and `historical place`. Based on this input function should return a `String` with this format. 177 | 178 | **My state population is ** Its traditional food is ** and historical place name is \_\_\_** 179 | 180 | **3.2:** Create a **function expression** which does the exact same thing as defined in **Question 1** 181 | 182 | **3.3:** Create function **addition** which takes two numbers as an argument And return the result of **sum of two numbers** 183 | 184 | **Important Note**: In the function call you are **not** passing any **parameter**. You can modify function to achieve this. 185 | 186 | _[From video lecture 3.2]_ 187 | 188 | ```js 189 | Example; 190 | 191 | function addition(num1, num2) { 192 | return num1 + num2; 193 | } 194 | 195 | console.log(addition()); //You are not allowed to modify this line any more 196 | ``` 197 | 198 | **3.4:** Identify which **type** of value passed below into the function **greet()**. What will be the return value of greet ? 199 | 200 | ```js 201 | let person = { 202 | name: 'john', 203 | 204 | age: 25, 205 | }; 206 | 207 | function greet(person) { 208 | person.name = `Mr ${person.name}`; 209 | 210 | return `Welcome ${person.name}`; 211 | } 212 | 213 | greet(person); 214 | ``` 215 | 216 | **3.5:** Create **higher** order function named as `transformer` which take `string` and `firstUpperCaseWord` function as an arguments. `firstUpperCaseWord` is function which make first word UpperCase from a given `String`. 217 | 218 | _[From video lecture 3.5]_ 219 | 220 | **3.6:** create function which will display Your name after every 5 seconds 221 | 222 | _[From video lecture 3.8]_ 223 | 224 | ```js 225 | 226 | input 227 | 228 | let yourName = "john"; 229 | 230 | 231 | 232 | output 233 | 234 | "john" after 5 second 235 | 236 | "john" after 5 second 237 | 238 | "john" after 5 second 239 | 240 | "john" after 5 second 241 | 242 | . 243 | 244 | . 245 | 246 | . 247 | 248 | and so on. 249 | 250 | ``` 251 | 252 | **3.7:** Guess the **Output** And Explain Why? 253 | 254 | _[From video lecture 3.4]_ 255 | 256 | ```js 257 | let arrowFunction = (name = 'Coders') => { 258 | `Welcome ${name}`; 259 | }; 260 | 261 | console.log(arrowFunction('Programmers')); 262 | ``` 263 | 264 | **3.8:** Create a JavaScript **Function** to find the area of a triangle where lengths of the three of its sides are 5, 6, 7. : **Area = Square root of√s(s - a)(s - b)(s - c)** where **s** is half the perimeter, or **(a + b + c)/2**. 265 | 266 | ```js 267 | input: area_of_triangle(5, 6, 7); 268 | 269 | output: 14.69; 270 | ``` 271 | 272 | **3.9:** Create a JavaScript **Function** to capitalize the first letter of each word of a given string. 273 | 274 | ```js 275 | input: capitalize('we are the champions'); 276 | 277 | output: 'We Are The Champions'; 278 | ``` 279 | 280 | ## Chapter 4 (Objects) 281 | 282 | ### Assignments 283 | 284 | **4.1:** Guess the **Output** And Explain ? 285 | 286 | ```js 287 | console.log(Math.round(Math.random() * 10)); 288 | ``` 289 | 290 | **4.2:** Create an object called `country` for a country of your choice, containing properties `name` , `capital`, `language`, `population` and `neighbors` 291 | 292 | 1. Increase the country population by two million using **dot** notation. 293 | 2. Decrease the country population by one million using **bracket** notation. 294 | 3. Make `language` value in Uppercase. 295 | 296 | _[From video lecture 4.1]_ 297 | 298 | **4.3:** Guess the **Output** and explain Why? 299 | 300 | ```js 301 | let car = { 302 | color: 'Blue', 303 | 304 | model: 2021, 305 | 306 | company: 'Toyota', 307 | }; 308 | 309 | let carColor = 'Blue'; 310 | 311 | console.log(car[carColor]); 312 | 313 | console.log(car.carColor); 314 | ``` 315 | 316 | **4.4:** Create a method **describeCar** inside `car` object in which you have to print like this in console using template literals 317 | 318 | _[From video lecture 4.3]_ 319 | 320 | **Company of my car is ** . It color is** And Model of my car is \_\_** 321 | 322 | **4.5:** Generate random numbers between 0 and 10 using **trunc** method of **MATH** object 323 | 324 | ```js 325 | 326 | Example 327 | 328 | getRandomNumbers(){ 329 | 330 | 331 | 332 | } 333 | 334 | Ouput value 0-10 335 | 336 | ``` 337 | 338 | **4.6:** Guess the **Output** and Explain Why? 339 | 340 | _[From video lecture 4.4]_ 341 | 342 | ```js 343 | 344 | let arr = [1,2,3,4]; 345 | 346 | arr.forEach(elem =>{ 347 | 348 | if(elem == 1){ 349 | 350 | continue; 351 | 352 | } 353 | 354 | console.log(elem); 355 | 356 | }) 357 | 358 | ``` 359 | 360 | **4.7:** Guess the **Output** And explain Why? 361 | 362 | **Important Note**: if there is any error, How we can solve that **error**? 363 | 364 | _[From video lecture 4.7]_ 365 | 366 | ```js 367 | let airplane = { 368 | flightName: 'fly india', 369 | 370 | atacode: 'FI', 371 | 372 | ratings: 4.9, 373 | 374 | book(passenger, flightNum) { 375 | console.log( 376 | `${passenger} Booked flight in ${this.flightName} with flight Number ${this.atacode}${flightNum}` 377 | ); 378 | }, 379 | }; 380 | 381 | let bookMethod = airplane.book; 382 | 383 | bookMethod('john', 8754); 384 | ``` 385 | 386 | **4.8:** Guess the **Output** And Explain Why? 387 | 388 | _[From video lecture 4.9]_ 389 | 390 | ```js 391 | let arr = [1, 2, 3, 4]; 392 | 393 | for (let elem in arr) { 394 | console.log(elem); 395 | } 396 | ``` 397 | 398 | **4.9:** You have to create a **Shopping_Cart** array with following features : 399 | 400 | - **addItem(itemName)** : this function should add string itemName to cart 401 | 402 | - **removeItem(itemName)**: this function should remove any item which matches itemName. _Hint : search for index of itemName and then remove it_ 403 | 404 | - **cartSize()** : returns size of cart in terms of number of cart Items. 405 | 406 | ## Chapter 5 (DOM) 407 | 408 | ### Assignments 409 | 410 | **5.1:** Explain difference between **innerText** and **innerHTML** in the following example? 411 | 412 | _[From video lecture 5.4]_ 413 | 414 | **HTML** 415 | 416 | ```html 417 |
418 |

Hello Coders

419 |
420 | ``` 421 | 422 | **JavaScript** 423 | 424 | ```js 425 | let content = document.getElementById('content'); 426 | 427 | console.log(content.innerHTML); 428 | 429 | console.log(content.innerText); 430 | ``` 431 | 432 | ## Chapter 6 ( DOM - Forms ) 433 | 434 | ### Assignments 435 | 436 | **6.1:** Create regex for password with the following **validations**. 437 | 438 | 1. Length of password at least of 8 characters 439 | 440 | 2. contain at least one special character 441 | 442 | 3. contain at least one alphabet (a-z) character 443 | 444 | _[From video lecture 6.2]_ 445 | 446 | **HTML** 447 | 448 | ```html 449 |
450 | 456 | 457 | 458 |
459 | ``` 460 | 461 | **JavaScript** 462 | 463 | ```js 464 | let form = document.querySelector('.testForm'); 465 | 466 | let inputPassword = document.querySelector('.inputPass'); 467 | 468 | let requiredPasswordPattern = 'create your regex here'; 469 | 470 | form.addEventListener('submit', (e) => { 471 | e.preventDefault(); 472 | 473 | let password = inputPassword.value; 474 | 475 | let result = requiredPasswordPattern.test(password); 476 | 477 | if (result == true) { 478 | console.log('Your password validated successfully'); 479 | } else { 480 | console.log('try again with new password'); 481 | } 482 | }); 483 | ``` 484 | 485 | ## Chapter 7 (Array Methods) 486 | 487 | ### Assignments 488 | 489 | **7.1:** You have given array of **strings**. Your task is to obtain last **two** elements of given array using **slice** method? 490 | 491 | ```js 492 | Input; 493 | 494 | let admins = ['john', 'paul', 'Neha', 'harry']; 495 | 496 | Ouput[('Neha', 'harry')]; 497 | ``` 498 | 499 | **7.2:** You have given an array of **5** elements(1-5). Your task is defined as below. 500 | 501 | _[From video lecture 7.2]_ 502 | 503 | ```js 504 | const arr = [1, 4, 7, 6, 8]; 505 | ``` 506 | 507 | 1. You have to delete **2** elements starting from index **2**. 508 | 509 | 2. You have to add **3** new elements on index **1** choice. 510 | 511 | 3. Display the **2 deleted** elements in console (from step 1) 512 | 513 | **7.3:** What happens if we use **negative** number inside **slice** method? 514 | 515 | ```js 516 | const arr = [1, 4, 7, 6, 8]; 517 | ``` 518 | 519 | Example : arr.slice(-2); 520 | 521 | **7.4:** Write **three** different methods/approaches to get **last** element of the array? 522 | 523 | ```js 524 | const arr = [1, 4, 7, 6, 8]; 525 | ``` 526 | 527 | _[From video lecture 7.3]_ 528 | 529 | **7.5:** You have given an array of **nums**. Create new Array with the help of **nums** array. In new Array each element will be a result of **multiplication by 2** of the original array element 530 | 531 | ```js 532 | const arr = [1, 4, 7, 6, 8]; 533 | ``` 534 | 535 | _[From video lecture 7.4]_ 536 | 537 | ```js 538 | Example: Input; 539 | 540 | let nums = [1, 2, 3, 4, 5]; 541 | 542 | output; 543 | 544 | updatedNums = [2, 4, 6, 8, 10]; 545 | ``` 546 | 547 | **7.6** You have given an array of **scores** in which score of each student stored. Create a new array with the help of original **scores** array in which only those scores exist **greater** than 75% 548 | 549 | ```js 550 | const arr = [10, 40, 70, 60, 80]; 551 | ``` 552 | 553 | _[From video lecture 7.5]_ 554 | 555 | ```js 556 | let totalScore = 150; 557 | 558 | let scores = [55, 76, 35, 77, 88, 97, 120, 136, 140]; 559 | ``` 560 | 561 | **7.7:** You have given an array of numbers **nums**. You have to find **sum** of all array elements using **reduce** method? 562 | 563 | ```js 564 | let nums = [2, 3, 5, 7, 8, 4, 9]; 565 | ``` 566 | 567 | **7.8:** You have given an array of numbers **nums**. You have to find the index of value **8** using **built-in** method of array? 568 | 569 | ```js 570 | let nums = [2, 3, 5, 6, 8, 6, 4, 8]; 571 | ``` 572 | 573 | **7.9:** You have given an array of **objects** of users as below. Find the specified **user** with `name = "John" ` 574 | 575 | Also find the **position** `(index+1)` of that **user** inside the array? 576 | 577 | ```js 578 | let users = [ 579 | { 580 | name: 'Paul', 581 | 582 | age: 24, 583 | 584 | verified: true, 585 | }, 586 | 587 | { 588 | name: 'John', 589 | 590 | age: 21, 591 | 592 | verified: false, 593 | }, 594 | 595 | { 596 | name: 'Neha', 597 | 598 | age: 19, 599 | 600 | verify: true, 601 | }, 602 | ]; 603 | ``` 604 | 605 | **7.10:** Guess the **Output** and explain Why? 606 | 607 | ```js 608 | let nums = [1, 2, 4, 5, [6, [8]], [9, 0]]; 609 | 610 | let res1 = nums.flat(1); 611 | 612 | let res2 = nums.flatMap((elem) => elem); 613 | 614 | console.log(res1, res2); 615 | ``` 616 | 617 | **7.11:** You have given an array of `nums`. Write a program to `sort` the elements of array in `descending` order **using built-in** method of array. 618 | 619 | ```js 620 | Input; 621 | 622 | let nums = [5, 1, 4, 6, 8, 3, 9]; 623 | 624 | Output[(9, 8, 6, 5, 4, 3, 1)]; 625 | ``` 626 | 627 | **7.12:** Guess the **Output** and Explain Why? 628 | 629 | _[From video lecture 7.13]_ 630 | 631 | ```js 632 | let arr = [1, 2, 3, 4]; 633 | 634 | let result = arr.splice(1, 2).pop(); 635 | 636 | console.log(result); 637 | ``` 638 | 639 | **7.13:** You have given an array of numbers `nums` You have to check if all elements of the **array > 15** using **built-in** array method. return `true` or `false` 640 | 641 | _[From video lecture 7.9]_ 642 | 643 | ```js 644 | let nums = [16, 17, 18, 28, 22]; 645 | ``` 646 | 647 | ### More Practice Questions (Arrays) 648 | 649 | **Question 1:** Guess the **Output** And explain Why? 650 | 651 | ```js 652 | let strArray = [1, 2, 3, 4, 5]; 653 | 654 | let result = strArray.reverse(); 655 | 656 | console.log(result == strArray); 657 | ``` 658 | 659 | **Question 2:** You have **given** two **arrays** below as an example. Your task is to **combine** them into one By using array method 660 | 661 | ```js 662 | input; 663 | 664 | let arr1 = [1, 2, 3, 4, 5]; 665 | 666 | let arr2 = [6, 7, 8, 9, 10]; 667 | 668 | ouput[(6, 7, 8, 9, 10, 1, 2, 3, 4, 5)]; 669 | ``` 670 | 671 | **Question 3:** You have given an array of **letters** below. Convert that array into string of letters **Without Space** 672 | 673 | ```js 674 | input; 675 | 676 | let arr = ['a', 'b', 'h', 'i', 's', 'h', 'e', 'k']; 677 | 678 | output; 679 | 680 | ('abhishek'); 681 | ``` 682 | 683 | **Question 4:** Guess the **Output** and explain why? 684 | 685 | ```js 686 | let arr = [11, 62, 1, 27, 8, 5]; 687 | 688 | let sorted = arr.sort(); 689 | 690 | console.log(sorted); 691 | ``` 692 | 693 | **Question 5:** Create a function 'calcAverageHumanAge', which accepts an arrays of dog's ages ('ages'), and does the following thing in order: 694 | 695 | 1. Calculate the dog `age` in human years using the following formula: if the `dogAge <= 2 years` old, `humanAge = 2 \* dogAg`e. If the `dog is > 2 years` old, `humanAge = 16 + dogAge` 696 | 697 | ```js 698 | 699 | Test data 700 | 701 | 702 | 703 | let arr = [12,2,5,12,8,13,9]; 704 | 705 | ``` 706 | 707 | **Question 6:** Guess the **Output** and Explain Why? 708 | 709 | ```js 710 | let arr = [1, 2, 3, 4, 5, 6, 7, 8]; 711 | 712 | let elem = arr.at(-1); 713 | 714 | console.log(elem); 715 | ``` 716 | 717 | **Question 7:** Guess the **Output** and Explain why? 718 | 719 | ```js 720 | let arr = [1, 2, 3, 4, 5, 6, 7, 8]; 721 | 722 | let result = arr.slice(2, 5).splice(0, 2, 21).pop(); 723 | 724 | console.log(result, arr); 725 | ``` 726 | 727 | ## Chapter 8 (Date) 728 | 729 | ### Assignments 730 | 731 | **8.1:** How can we get current time in **millisecond** of current time? 732 | 733 | **8.2:** Guess the **Output** and Explain Why? 734 | 735 | _[From video lecture 8.2]_ 736 | 737 | ```js 738 | let currentDate = new Date(); 739 | 740 | let result1 = currentDate.getDay(); 741 | 742 | let result2 = currentDate.getDate(); 743 | 744 | console.log(result1, result2); 745 | ``` 746 | 747 | ## Chapter 9 (LocalStorage) 748 | 749 | ### Assignments 750 | 751 | **9.1:** Create two variables **myHobby** , **age** . Now **set** their value in local storage (according to your hobby and age). 752 | 753 | After setting also **get** value from local storage and display their values in **console**. 754 | 755 | _[From video lecture 9.2]_ 756 | 757 | ## Chapter 10 (OOP) 758 | 759 | ### Assignments 760 | 761 | **10.1:** Your tasks: 762 | 763 | 1. Use a **constructor** function to implement a `Bike`. A bike has a `make` and a `speed` property. The `speed` property is the current speed of the bike in km/h 764 | 765 | 2. Implement an `accelerate` method that will increase the bike's speed by **50**, and log the new speed to the console 766 | 767 | 3. Implement a `brake` method that will decrease the bike's speed by **25**, and log the new speed to the console 768 | 769 | 4. Create **2** 'Bike' objects and experiment with calling `accelerate` and `brake` multiple times on each of them 770 | 771 | **Sample Data** 772 | 773 | Data car 1: `bike1` going at 120 km/h 774 | 775 | Data car 2: `bike` going at 95 km/h 776 | 777 | **10.2:** Re-create **Question 1** But this time using **ES6** 778 | 779 | class. 780 | 781 | _[From video lecture 10.4]_ 782 | 783 | **10.3:** Guess the **Output** And Explain Why? 784 | 785 | _[From video lecture 10.2]_ 786 | 787 | ```js 788 | function Person(name) { 789 | this.name = name; 790 | } 791 | 792 | let me = new Person('John'); 793 | 794 | console.log(me.__proto__ == Person.prototype); 795 | 796 | console.log(me.__proto__.__proto__ == Object.prototype); 797 | ``` 798 | 799 | **10.4:** Create **constructor** function inside **Car** class with three properties **color** , **model** , **company** 800 | 801 | ```js 802 | class Car {} 803 | ``` 804 | 805 | **10.5:** **Identify** all **mistakes** in the following class 806 | 807 | ```js 808 | 809 | class Car = { 810 | 811 | constructor(){ 812 | 813 | 814 | 815 | }, 816 | 817 | engineMethod = function(){ 818 | 819 | console.log("This is engine method of Car class"); 820 | 821 | } 822 | 823 | } 824 | 825 | ``` 826 | 827 | **10.6:** Guess the **Output** and explain Why? And **if** there is any **error** How we can remove that error? 828 | 829 | _[From video lecture 10.6]_ 830 | 831 | ```js 832 | function Person(name, age) { 833 | this.name = name; 834 | 835 | this.age = age; 836 | 837 | this.brainMethod = function () { 838 | console.log('This is brain method of Person'); 839 | }; 840 | } 841 | 842 | Person.heartMethod = function () { 843 | console.log('This is heart method of Person'); 844 | }; 845 | 846 | let me = new Person('john', 34); 847 | 848 | me.brainMethod(); 849 | 850 | me.heartMethod(); 851 | ``` 852 | 853 | **10.7:** Create a new class `Dog` (which will be child class) inherited from `Animal` class. In Addition in `Dog` class add some additional properties like **breedType** 854 | 855 | _[From video lecture 10.7]_ 856 | 857 | **Question 8:** Guess the **Output** And Explain Why? 858 | 859 | ```js 860 | class Car { 861 | constructor() {} 862 | } 863 | 864 | let car = new Car(); 865 | 866 | console.log(Car.prototype.isPrototypeOf(Car)); 867 | 868 | console.log(Car.prototype.isPrototypeOf(car)); 869 | ``` 870 | 871 | ### More Practice Questions (OOP) 872 | 873 | **Question 1:** Guess the **Output** and Explain Why? 874 | 875 | ```js 876 | function carObject(name, model) { 877 | let car = Object.create(constructorObject); 878 | 879 | car.name = name; 880 | 881 | car.model = model; 882 | 883 | this.engineMethod = function () { 884 | console.log('This is engine method of car'); 885 | }; 886 | 887 | return car; 888 | } 889 | 890 | let constructorObject = { 891 | speak: function () { 892 | return 'This is my car'; 893 | }, 894 | }; 895 | 896 | let myCar = carObject('Audi', 2023); 897 | 898 | console.log(myCar.__proto__); 899 | ``` 900 | 901 | **Question 2:** You have given an example of **OOP** Code. Your task is to explain the use of `super` keyword in `Dog` class. 902 | 903 | And you have to **change** the code again after removing `super` keyword from the `Dog` class (You have remove those lines/statements which are not **necessary** after **removing** super **keyword**) 904 | 905 | ```js 906 | class Animals { 907 | constructor(name, age) { 908 | this.name = name; 909 | 910 | this.age = age; 911 | } 912 | 913 | sing() { 914 | return `${this.name} can sing`; 915 | } 916 | 917 | dance() { 918 | return `${this.name} can dance`; 919 | } 920 | } 921 | 922 | class Dogs extends Animals { 923 | constructor(name, age, whiskerColor) { 924 | super(name, age); 925 | 926 | this.whiskerColor = whiskerColor; 927 | } 928 | 929 | whiskers() { 930 | return `I have ${this.whiskerColor} whiskers`; 931 | } 932 | } 933 | 934 | let newDog = new Dogs('Clara', 33, 'indigo'); 935 | 936 | console.log(newDog); 937 | ``` 938 | 939 | **Question 3:** What are the advantages of using **getter** and **setter** method in OOP? 940 | 941 | **Question 4:** You have OOP code below. And there is **single** error in this code? Your task is to **remove that error**. 942 | 943 | **Important Note**: To solve this error You need to know about **method chaining** concept. 944 | 945 | ```js 946 | class Car { 947 | constructor(id) { 948 | this.id = id; 949 | } 950 | 951 | setMake(make) { 952 | this.make = make; 953 | } 954 | 955 | setModel(model) { 956 | this.model = model; 957 | } 958 | 959 | setFuelType(fuelType) { 960 | this.fuelType = fuelType; 961 | } 962 | 963 | getCarInfo() { 964 | return { 965 | id: this.id, 966 | 967 | make: this.make, 968 | 969 | model: this.model, 970 | 971 | fuelType: this.fuelType, 972 | }; 973 | } 974 | } 975 | 976 | console.log( 977 | new Car(233) 978 | 979 | .setMake('Honda') 980 | 981 | .setModel('Civic') 982 | 983 | .setFuelType('Petrol') 984 | 985 | .getCarInfo() 986 | ); 987 | ``` 988 | 989 | **Question 5:** What is difference between ** proto** and prototype property of Object? Try with **Example**? 990 | 991 | **Question 6:** create class of `Person` with properties `name`, `age`. 992 | 993 | Your main task is to add `static` method in that class of your choice ( e.g brainMethod) 994 | 995 | ```js 996 | class Person { 997 | constructor(name, age) { 998 | this.name = name; 999 | 1000 | this.age = age; 1001 | } 1002 | } 1003 | 1004 | let me = new Person('abhishek', 25); 1005 | 1006 | console.log(me); 1007 | ``` 1008 | 1009 | ## Chapter 11( Async Js ) 1010 | 1011 | ### Assignments 1012 | 1013 | **11.1:** Guess the **Output** And Explain Why? 1014 | 1015 | _[From video lecture 11.7]_ 1016 | 1017 | **Html Code** 1018 | 1019 | ```html 1020 | 1021 | 1022 | 1023 | 1024 | 1025 | 1026 | 1027 | 1028 | 1029 | 1030 | 1031 | 1032 | 1033 | JavaScript-CoderDost 1034 | 1035 |