You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
1.10: If your State is split intofour equal parts such that in each part there are1/4 number of people live. You have to find how many people would live in each part? which operators will you use ?
2.3: Write a simpleProgram in which You have to print first10 numbers indescending order (10...1)?
2.4: Lets sayJohn is looking a newcountry to live in. He want to live in a country that speaksEnglish, has less than 10 million people. One of thefood option between these two must presentSpanish food OREnglish food.
Write an if/else if statement to help john figure out Your country is right for him?
Ifboth true show any message(I can sit in exam) in the console?
2.7: Create two variablesgrade andpassingYear.Check if yourgrade == "A" andpassingYear < 2020 with the help ofternary operator(Not allowed to use any logical operator).If both conditiontrue print on consoleQualify. OtherwiseFail
[From video lecture 2.9]
Chapter 3 (Functions)
Assignments
3.1: Create afunction Declaration calleddescribeYourState Which take three parametersPopulation,traditional food andhistorical place. Based on this input function should return aString with this format.
My state population is ** Its traditional food is ** and historical place name is ___
3.2: Create afunction expression which does the exact same thing as defined inQuestion 1
3.3: Create functionaddition which takes two numbers as an argument And return the result ofsum of two numbers
Important Note: In the function call you arenot passing anyparameter. You can modify function to achieve this.
[From video lecture 3.2]
Example;functionaddition(num1,num2){returnnum1+num2;}console.log(addition());//You are not allowed to modify this line any more
3.4: Identify whichtype of value passed below into the functiongreet(). What will be the return value of greet ?
3.5: Createhigher order function named astransformer which takestring andfirstUpperCaseWord function as an arguments.firstUpperCaseWord is function which make first word UpperCase from a givenString.
[From video lecture 3.5]
3.6: create function which will display Your name after every 5 seconds
3.8: Create a JavaScriptFunction 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) wheres is half the perimeter, or(a + b + c)/2.
input:area_of_triangle(5,6,7);output:14.69;
3.9: Create a JavaScriptFunction to capitalize the first letter of each word of a given string.
input:capitalize('we are the champions');output:'We Are The Champions';
Chapter 4 (Objects)
Assignments
4.1: Guess theOutput And Explain ?
console.log(Math.round(Math.random()*10));
4.2: Create an object calledcountry for a country of your choice, containing propertiesname ,capital,language,population andneighbors
Increase the country population by two million usingdot notation.
Decrease the country population by one million usingbracket notation.
letform=document.querySelector('.testForm');letinputPassword=document.querySelector('.inputPass');letrequiredPasswordPattern='create your regex here';form.addEventListener('submit',(e)=>{e.preventDefault();letpassword=inputPassword.value;letresult=requiredPasswordPattern.test(password);if(result==true){console.log('Your password validated successfully');}else{console.log('try again with new password');}});
Chapter 7 (Array Methods)
Assignments
7.1: You have given array ofstrings. Your task is to obtain lasttwo elements of given array usingslice method?
7.2: You have given an array of5 elements(1-5). Your task is defined as below.
[From video lecture 7.2]
constarr=[1,4,7,6,8];
You have to delete2 elements starting from index2.
You have to add3 new elements on index1 choice.
Display the2 deleted elements in console (from step 1)
7.3: What happens if we usenegative number insideslice method?
constarr=[1,4,7,6,8];
Example : arr.slice(-2);
7.4: Writethree different methods/approaches to getlast element of the array?
constarr=[1,4,7,6,8];
[From video lecture 7.3]
7.5: You have given an array ofnums. Create new Array with the help ofnums array. In new Array each element will be a result ofmultiplication by 2 of the original array element
7.6 You have given an array ofscores in which score of each student stored. Create a new array with the help of originalscores array in which only those scores existgreater than 75%
Question 5: Create a function 'calcAverageHumanAge', which accepts an arrays of dog's ages ('ages'), and does the following thing in order:
Calculate the dogage in human years using the following formula: if thedogAge <= 2 years old,humanAge = 2 \* dogAge. If thedog is > 2 years old,humanAge = 16 + dogAge
10.4: Createconstructor function insideCar class with three propertiescolor ,model ,company
classCar{}
10.5:Identify allmistakes in the following class
classCar={constructor(){},engineMethod=function(){console.log("This is engine method of Car class");}}
10.6: Guess theOutput and explain Why? Andif there is anyerror How we can remove that error?
[From video lecture 10.6]
functionPerson(name,age){this.name=name;this.age=age;this.brainMethod=function(){console.log('This is brain method of Person');};}Person.heartMethod=function(){console.log('This is heart method of Person');};letme=newPerson('john',34);me.brainMethod();me.heartMethod();
10.7: Create a new classDog (which will be child class) inherited fromAnimal class. In Addition inDog class add some additional properties likebreedType
functioncarObject(name,model){letcar=Object.create(constructorObject);car.name=name;car.model=model;this.engineMethod=function(){console.log('This is engine method of car');};returncar;}letconstructorObject={speak:function(){return'This is my car';},};letmyCar=carObject('Audi',2023);console.log(myCar.__proto__);
Question 2: You have given an example ofOOP Code. Your task is to explain the use ofsuper keyword inDog class.
And you have tochange the code again after removingsuper keyword from theDog class (You have remove those lines/statements which are notnecessary afterremoving superkeyword)
classAnimals{constructor(name,age){this.name=name;this.age=age;}sing(){return`${this.name} can sing`;}dance(){return`${this.name} can dance`;}}classDogsextendsAnimals{constructor(name,age,whiskerColor){super(name,age);this.whiskerColor=whiskerColor;}whiskers(){return`I have${this.whiskerColor} whiskers`;}}letnewDog=newDogs('Clara',33,'indigo');console.log(newDog);
Question 3: What are the advantages of usinggetter andsetter method in OOP?
Question 4: You have OOP code below. And there issingle error in this code? Your task is toremove that error.
Important Note: To solve this error You need to know aboutmethod chaining concept.
asyncfunctiongreeting(){letmyPromise=newPromise(function(resolve){setTimeout(function(){resolve('I love Programming !!');},2000);});document.getElementById('heading').innerHTML=awaitmyPromise;}greeting();
11.2: Find theLogical Error in below code. And How can we solve them withcallback function approach?
12.7: You have given an object as below. You have to check wheatherphysics is the subject of that student or not, if true find thescore ofphysics subject usingoptional chaining
13.1: You have given scenario. You are inscript.js And in same directory there is another fileproducts.js. Inproducts.js there are two methods calledcreateProduct anddeleteProduct
write animport andexport statement properly in order to import these two methods fromproducts.js file into thescript.js
Question 2 Nowexport only one methodcreateProduct usingdefault export statement?
Question 3: Inimport statement how can wecustomize/change the name offunction we are importing?
Example : function is defined asAddition. We want to import as 'Add'
How can can we do this?
About
JavaScript course for beginners on CoderDost Youtube Channel