Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

JavaScript course for beginners on CoderDost Youtube Channel

NotificationsYou must be signed in to change notification settings

conditional-statement/JavaScript-Course-2023

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 

Repository files navigation

Note: More questions to be updated in 24 Hours.

Chapter 1 (Data Types)

Assignments

1.1: Create a code to check difference betweennull andundefined data type. Also check their type usingtypeof.

1.2: Which type of variables (var, let or const) must beinitialized at the time of declaration?

1.3: Guess theOutput and Explain Why?

[From video lecture 1.5]

letlanguages='java javaScript python cSharp';letresult=languages.lastIndexOf('S');console.log(result);

1.4: Guess theOutput and Explain Why?

[From video lecture 1.8]

letvariable='hello programmers';letresult=Number(variable);console.log(result);

1.5: Guess theOutput and Explain Why?

letnum1=32;letnum2='32';letresult1=num1!==num2;letresult2=num1!=num2;console.log(result1,result2);

1.6: Guess theOutput and explain Why?

letstr='Hello Programmers';letresult=str.includes('r');console.log(result);

1.7: Guess theOutput and Explain Why?

[From video lecture 1.6]

letnum1=2;letnum2=5;letresult=num1**num2*2;console.log(result);

1.8: Guess theOutput and Explain Why?

letnum1=[1,2,4,5];letnum2=[6,5,8,0];letresult=num1.concat(num2);console.log(result);

1.9: Guess theOutput and Explain Why?

leta=5;letb=7;letc=8;letresult=a<b>c;console.log(result);

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 ?

[From video lecture 1.6]

Chapter 2 (Control Flow / Conditional)

Assignments:

2.1: Guess theOutput And Explain Why?

leti=4;for(letj=0;i<10;i++){if(j===1||i===6){continue;}else{console.log(i,j);if(i===7){break;}}}

2.2: Guess theOutput and Explain Why?

leti=0;for(i;i<5;i++){console.log(i);}

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?

[From video lecture 2.4]

2.5: Guess theOutput And Explain Why?

for(leti=0;i<10;i++){console.log(i);}console.log(i);

2.6: usenested-if statement to check yourage>18

than check your heightheight > 5.10.

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 ?

letperson={name:'john',age:25,};functiongreet(person){person.name=`Mr${person.name}`;return`Welcome${person.name}`;}greet(person);

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

[From video lecture 3.8]

inputletyourName="john";output"john"after5second"john"after5second"john"after5second"john"after5second...andsoon.

3.7: Guess theOutput And Explain Why?

[From video lecture 3.4]

letarrowFunction=(name='Coders')=>{`Welcome${name}`;};console.log(arrowFunction('Programmers'));

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

  1. Increase the country population by two million usingdot notation.
  2. Decrease the country population by one million usingbracket notation.
  3. Makelanguage value in Uppercase.

[From video lecture 4.1]

4.3: Guess theOutput and explain Why?

letcar={color:'Blue',model:2021,company:'Toyota',};letcarColor='Blue';console.log(car[carColor]);console.log(car.carColor);

4.4: Create a methoddescribeCar insidecar object in which you have to print like this in console using template literals

[From video lecture 4.3]

Company of my car is ** . It color is And Model of my car is __**

4.5: Generate random numbers between 0 and 10 usingtrunc method ofMATH object

ExamplegetRandomNumbers(){}Ouputvalue0-10

4.6: Guess theOutput and Explain Why?

[From video lecture 4.4]

letarr=[1,2,3,4];arr.forEach(elem=>{if(elem==1){continue;}console.log(elem);})

4.7: Guess theOutput And explain Why?

Important Note: if there is any error, How we can solve thaterror?

[From video lecture 4.7]

letairplane={flightName:'fly india',atacode:'FI',ratings:4.9,book(passenger,flightNum){console.log(`${passenger} Booked flight in${this.flightName} with flight Number${this.atacode}${flightNum}`);},};letbookMethod=airplane.book;bookMethod('john',8754);

4.8: Guess theOutput And Explain Why?

[From video lecture 4.9]

letarr=[1,2,3,4];for(leteleminarr){console.log(elem);}

4.9: You have to create aShopping_Cart array with following features :

  • addItem(itemName) : this function should add string itemName to cart

  • removeItem(itemName): this function should remove any item which matches itemName.Hint : search for index of itemName and then remove it

  • cartSize() : returns size of cart in terms of number of cart Items.

Chapter 5 (DOM)

Assignments

5.1: Explain difference betweeninnerText andinnerHTML in the following example?

[From video lecture 5.4]

HTML

<divid="content"><h2>Hello Coders</h2></div>

JavaScript

letcontent=document.getElementById('content');console.log(content.innerHTML);console.log(content.innerText);

Chapter 6 ( DOM - Forms )

Assignments

6.1: Create regex for password with the followingvalidations.

  1. Length of password at least of 8 characters

  2. contain at least one special character

  3. contain at least one alphabet (a-z) character

[From video lecture 6.2]

HTML

<formaction=""class="testForm"><inputtype="password"name=""class="inputPass"placeholder="Enter Password"/><inputtype="submit"value="Check Password"/></form>

JavaScript

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?

Input;letadmins=['john','paul','Neha','harry'];Ouput[('Neha','harry')];

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];
  1. You have to delete2 elements starting from index2.

  2. You have to add3 new elements on index1 choice.

  3. 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

constarr=[1,4,7,6,8];

[From video lecture 7.4]

Example:Input;letnums=[1,2,3,4,5];output;updatedNums=[2,4,6,8,10];

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%

constarr=[10,40,70,60,80];

[From video lecture 7.5]

lettotalScore=150;letscores=[55,76,35,77,88,97,120,136,140];

7.7: You have given an array of numbersnums. You have to findsum of all array elements usingreduce method?

letnums=[2,3,5,7,8,4,9];

7.8: You have given an array of numbersnums. You have to find the index of value8 usingbuilt-in method of array?

letnums=[2,3,5,6,8,6,4,8];

7.9: You have given an array ofobjects of users as below. Find the specifieduser withname = "John"

Also find theposition(index+1) of thatuser inside the array?

letusers=[{name:'Paul',age:24,verified:true,},{name:'John',age:21,verified:false,},{name:'Neha',age:19,verify:true,},];

7.10: Guess theOutput and explain Why?

letnums=[1,2,4,5,[6,[8]],[9,0]];letres1=nums.flat(1);letres2=nums.flatMap((elem)=>elem);console.log(res1,res2);

7.11: You have given an array ofnums. Write a program tosort the elements of array indescending orderusing built-in method of array.

Input;letnums=[5,1,4,6,8,3,9];Output[(9,8,6,5,4,3,1)];

7.12: Guess theOutput and Explain Why?

[From video lecture 7.13]

letarr=[1,2,3,4];letresult=arr.splice(1,2).pop();console.log(result);

7.13: You have given an array of numbersnums You have to check if all elements of thearray > 15 usingbuilt-in array method. returntrue orfalse

[From video lecture 7.9]

letnums=[16,17,18,28,22];

More Practice Questions (Arrays)

Question 1: Guess theOutput And explain Why?

letstrArray=[1,2,3,4,5];letresult=strArray.reverse();console.log(result==strArray);

Question 2: You havegiven twoarrays below as an example. Your task is tocombine them into one By using array method

input;letarr1=[1,2,3,4,5];letarr2=[6,7,8,9,10];ouput[(6,7,8,9,10,1,2,3,4,5)];

Question 3: You have given an array ofletters below. Convert that array into string of lettersWithout Space

input;letarr=['a','b','h','i','s','h','e','k'];output;('abhishek');

Question 4: Guess theOutput and explain why?

letarr=[11,62,1,27,8,5];letsorted=arr.sort();console.log(sorted);

Question 5: Create a function 'calcAverageHumanAge', which accepts an arrays of dog's ages ('ages'), and does the following thing in order:

  1. 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
Testdataletarr=[12,2,5,12,8,13,9];

Question 6: Guess theOutput and Explain Why?

letarr=[1,2,3,4,5,6,7,8];letelem=arr.at(-1);console.log(elem);

Question 7: Guess theOutput and Explain why?

letarr=[1,2,3,4,5,6,7,8];letresult=arr.slice(2,5).splice(0,2,21).pop();console.log(result,arr);

Chapter 8 (Date)

Assignments

8.1: How can we get current time inmillisecond of current time?

8.2: Guess theOutput and Explain Why?

[From video lecture 8.2]

letcurrentDate=newDate();letresult1=currentDate.getDay();letresult2=currentDate.getDate();console.log(result1,result2);

Chapter 9 (LocalStorage)

Assignments

9.1: Create two variablesmyHobby ,age . Nowset their value in local storage (according to your hobby and age).

After setting alsoget value from local storage and display their values inconsole.

[From video lecture 9.2]

Chapter 10 (OOP)

Assignments

10.1: Your tasks:

  1. Use aconstructor function to implement aBike. A bike has amake and aspeed property. Thespeed property is the current speed of the bike in km/h

  2. Implement anaccelerate method that will increase the bike's speed by50, and log the new speed to the console

  3. Implement abrake method that will decrease the bike's speed by25, and log the new speed to the console

  4. Create2 'Bike' objects and experiment with callingaccelerate andbrake multiple times on each of them

Sample Data

Data car 1:bike1 going at 120 km/h

Data car 2:bike going at 95 km/h

10.2: Re-createQuestion 1 But this time usingES6

class.

[From video lecture 10.4]

10.3: Guess theOutput And Explain Why?

[From video lecture 10.2]

functionPerson(name){this.name=name;}letme=newPerson('John');console.log(me.__proto__==Person.prototype);console.log(me.__proto__.__proto__==Object.prototype);

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

[From video lecture 10.7]

Question 8: Guess theOutput And Explain Why?

classCar{constructor(){}}letcar=newCar();console.log(Car.prototype.isPrototypeOf(Car));console.log(Car.prototype.isPrototypeOf(car));

More Practice Questions (OOP)

Question 1: Guess theOutput and Explain Why?

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.

classCar{constructor(id){this.id=id;}setMake(make){this.make=make;}setModel(model){this.model=model;}setFuelType(fuelType){this.fuelType=fuelType;}getCarInfo(){return{id:this.id,make:this.make,model:this.model,fuelType:this.fuelType,};}}console.log(newCar(233).setMake('Honda').setModel('Civic').setFuelType('Petrol').getCarInfo());

Question 5: What is difference between ** proto** and prototype property of Object? Try withExample?

Question 6: create class ofPerson with propertiesname,age.

Your main task is to addstatic method in that class of your choice ( e.g brainMethod)

classPerson{constructor(name,age){this.name=name;this.age=age;}}letme=newPerson('abhishek',25);console.log(me);

Chapter 11( Async Js )

Assignments

11.1: Guess theOutput And Explain Why?

[From video lecture 11.7]

Html Code

<!DOCTYPE  html><htmllang="en"><head><metacharset="UTF-8"><metahttp-equiv="X-UA-Compatible"content="IE=edge"><metaname="viewport"content="width=device-width, initial-scale=1.0"><title>JavaScript-CoderDost</title><style></head><body><div><h2 id = "heading" ></h2></div><script defer src = "./script.js"></script></script></body></html>

JS Code

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?

[From video lecture 11.4]

constmovies=[{title:`Movie 1`},{title:`Movie 2`}];functiongetMovies(){setTimeout(()=>{movies.forEach((movie,index)=>{console.log(movie.title);});},1000);}functioncreateMovies(movie){setTimeout(()=>{movies.push(movie);},2000);}getMovies();createMovies({title:`Movie 3`});

11.3: What are thethree possible State of any promise?

11.4: SolveQuestion 2 again But this time with the help ofpromise

11.5: Now re-factorQuestion 2 with the help ofasync-await keyword?

11.6: Status code starting with404 represent which type of message/error?

[From video lecture 11.3]

Chapter 12 (ES6)

Assignments

12.1: Guess theOutput and Explain Why?

[From video lecture 12.1]

letarr=[3,4,5,7,98,0];let[a,b,,c]=arr;console.log(a,b,c);

12.2: Guess theOutput And Explain Why?

[From video lecture 12.1]

letarr=[1,3,[2,55],[9,8,7]];let[a,,[b,c],d]=arr;console.log(a,b,c,d);

12.3: Guess theOutput and explain Why?

[From video lecture 12.2]

letobj={name:'John',age:25,weight:70,};let{name:objName, age}=obj;console.log(name,age);

12.4: You have given an array ofnums.Createshallow copy of that array and store them in anothervariable

[From video lecture 12.3]

letnums=[5,7,4,9,2,8];letnewNums="store Shallow copy of nums inside newNums variable")

12.5: You have given an array as below . Create a function which acceptmultiple elements as an argument and return last4 element of the array

[From video lecture 12.4]

Example:letnums=[1,2,3,4,5,6,7,8];inputdata:1,2,3,4,5,6,7,8outputdata:5,6,7,8

12.6: Guess theOutput And Explain Why?

[From video lecture 12.6]

letnums=0;letresult=nums??50;console.log(result);

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

letstudent={Math:{score:75,},physics:{score:85,},};

12.8: Guess theOutput And Explain Why?

[From video lecture 12.7]

letnums=[2,3,4,5,6];for(letkeyofnums){console.log(key);}

More Practice Questions

Question 1: Guess theOutput and Explain Why?

letarr=[1,2,3,4,5];letarr1=[...arr];arr1[2]=10;console.log(arr,arr1);

Question 2: You have given a list of variable names written in underscore. You have to write a program to convert them into camel casing format

ListofvariablenamesInputuser_namelast_namedate_of_birthuser_passwordOutputuserNamelastNamedateOfBirthuserPassword

Question 3: Guess theOutput and Explain why?

functionfun(a,b, ...c){console.log(`${a}${b}`);console.log(c);console.log(c[0]);console.log(c.length);console.log(c.indexOf('google'));}fun('apple','sumsung','amazon','google','facebook');

Question 4: Guess theOutput and Explain Why?

constfruits={apple:8,orange:7,pear:5};constentries=Object.entries(fruits);for(const[fruit,count]ofentries){console.log(`There are${count}${fruit}s`);}

Question 5: Write a program in which you have to setDefault value in case of false input value usingLogical Assignment Operator?

Question 6: Guess theOutput and Explain Why?

letarr=newSet([1,2,3,1,2,1,3,4,6,7,5]);letlength=arr.size;console.log(arr,length);

Question 7: You have givenSet below. Your task is to convert thatSet into anarray?

input;letset=newSet[(1,2,3,2,1,3,4,12,2)]();output;letarr='Do something here to convert....';

Question 8: Guess theOutput and Explain Why?

Note :Change values of variable to examine the result.

letnumber=40;letage=18;letresult=number>50 ?(age>19 ?'pass' :'ageIssue') :'numberIssue';console.log(result);

Chapter 13 (Modern Tooling)

Assignments

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp