├── 10 ├── doubleshot_lyst6532.js └── jsSort_lyst7387.js ├── .DS_Store ├── 05 ├── 01dom_lyst8650.zip ├── proj1_lyst1313.zip ├── proj2_lyst5378.zip └── proj2final_lyst1999.zip ├── 01 ├── 01Hello_lyst2590.zip ├── 01Variables_lyst6562.js ├── 02_Variables-two_lyst6907.js ├── 03_Operators_lyst3638.js └── 03_Operators_lyst7877.js ├── 09 ├── final-code_lyst4769.zip └── Get_to_know_game_files_lyst5685.zip ├── 06 ├── 03_function_lyst8189.js ├── 04_lexicalScoping_lyst7946.js ├── 02_ObjectsPartTwo_lyst8077.js ├── 05_Closure_lyst9236.js ├── 01_Objects_lyst2840.js └── 06_thisBinding_lyst7219.js ├── 08 ├── 01_scope_lyst5866.js ├── Classes-module-exports-javascript_lyst6422.zip ├── 02_strings_lyst1064.js ├── 10_API_lyst8229.js ├── 08_async_lyst8407.js ├── 04_pickData_lyst5294.js ├── 03_maps_lyst6550.js ├── 05_spread_lyst9584.js └── 09_Promise_lyst9698.js ├── 07 ├── 01_Get_to_know_node_Elements_in_Javascript_lyst3999.zip └── 02_Generating_elements_and_Text_node_in_DOM_lyst8834.zip ├── readme.md ├── 02 ├── 09_TruthyAndFalsy_lyst1171.js ├── 06_ConditionalLogin_lyst2886.js ├── 07_ConditionalSignout_lyst1248.js ├── 04_Conditional_lyst5979.js ├── 05_ConditionalPurchase_lyst2042.js └── 08_ConditionalRoles_lyst4025.js ├── 03 ├── 06_thisKeyword_lyst7635.js ├── 03_jsContext_lyst5285.js ├── 05_scopeChaining_lyst1592.js ├── 01_functions_lyst3526.js ├── 04_hoisting_lyst2895.js └── 02_userRoleFunction_lyst4182.js └── 04 ├── 10_Objects_lyst6054.js ├── 15_thisAgain_lyst7403.js ├── 13_loopsPartTwo_lyst6138.js ├── 08_arrayPartTwo_lyst7153.js ├── 14_loopsPartThree_lyst2770.js ├── 09_filterArray_lyst2301.js ├── 12_loops_lyst2766.js ├── 07_array_lyst8270.js └── 11_objectsPartTwo_lyst3320.js /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiteshchoudhary/javascript-youtube/HEAD/.DS_Store -------------------------------------------------------------------------------- /05/01dom_lyst8650.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiteshchoudhary/javascript-youtube/HEAD/05/01dom_lyst8650.zip -------------------------------------------------------------------------------- /05/proj1_lyst1313.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiteshchoudhary/javascript-youtube/HEAD/05/proj1_lyst1313.zip -------------------------------------------------------------------------------- /05/proj2_lyst5378.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiteshchoudhary/javascript-youtube/HEAD/05/proj2_lyst5378.zip -------------------------------------------------------------------------------- /01/01Hello_lyst2590.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiteshchoudhary/javascript-youtube/HEAD/01/01Hello_lyst2590.zip -------------------------------------------------------------------------------- /05/proj2final_lyst1999.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiteshchoudhary/javascript-youtube/HEAD/05/proj2final_lyst1999.zip -------------------------------------------------------------------------------- /09/final-code_lyst4769.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiteshchoudhary/javascript-youtube/HEAD/09/final-code_lyst4769.zip -------------------------------------------------------------------------------- /06/03_function_lyst8189.js: -------------------------------------------------------------------------------- 1 | (function () { 2 | console.log("I say hello"); 3 | console.log("I again say Hello"); 4 | })(); 5 | -------------------------------------------------------------------------------- /09/Get_to_know_game_files_lyst5685.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiteshchoudhary/javascript-youtube/HEAD/09/Get_to_know_game_files_lyst5685.zip -------------------------------------------------------------------------------- /08/01_scope_lyst5866.js: -------------------------------------------------------------------------------- 1 | //console.log(name); 2 | 3 | var name = "hitesh"; 4 | 5 | if (true) { 6 | let lastName = "Choudhary"; 7 | } 8 | console.log(lastName); 9 | -------------------------------------------------------------------------------- /08/Classes-module-exports-javascript_lyst6422.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiteshchoudhary/javascript-youtube/HEAD/08/Classes-module-exports-javascript_lyst6422.zip -------------------------------------------------------------------------------- /07/01_Get_to_know_node_Elements_in_Javascript_lyst3999.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiteshchoudhary/javascript-youtube/HEAD/07/01_Get_to_know_node_Elements_in_Javascript_lyst3999.zip -------------------------------------------------------------------------------- /07/02_Generating_elements_and_Text_node_in_DOM_lyst8834.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiteshchoudhary/javascript-youtube/HEAD/07/02_Generating_elements_and_Text_node_in_DOM_lyst8834.zip -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # welcome to javascript youtube series 2 | 3 | here are all code files 4 | 5 | [link to series](https://www.youtube.com/watch?v=2md4HQNRqJA&list=PLRAV69dS1uWSxUIk5o3vQY2-_VKsOpXLD) -------------------------------------------------------------------------------- /06/04_lexicalScoping_lyst7946.js: -------------------------------------------------------------------------------- 1 | function init() { 2 | var firstName = "hitesh"; 3 | function sayFirstName() { 4 | console.log(firstName); 5 | } 6 | sayFirstName(); 7 | } 8 | 9 | init(); 10 | -------------------------------------------------------------------------------- /10/doubleshot_lyst6532.js: -------------------------------------------------------------------------------- 1 | const google = "google"; 2 | const fb = null; 3 | 4 | if (google) { 5 | console.log("I execute - BLOCK 1"); 6 | } 7 | 8 | if (!!fb) { 9 | console.log("I execute - BLOCK 2"); 10 | } 11 | -------------------------------------------------------------------------------- /02/09_TruthyAndFalsy_lyst1171.js: -------------------------------------------------------------------------------- 1 | //TODO: falsy 2 | // undefined 3 | // null 4 | // 0 5 | // '' 6 | // NaN 7 | 8 | var user = "2"; 9 | 10 | if (2 === user) { 11 | console.log("Condition is true"); 12 | } 13 | 14 | // console.log("2" + "2"); 15 | -------------------------------------------------------------------------------- /03/06_thisKeyword_lyst7635.js: -------------------------------------------------------------------------------- 1 | //TODO: part 1 for this keyword 2 | 3 | console.log(this); 4 | 5 | var game = "basketball"; 6 | 7 | // function sayName() { 8 | // var name = "Hitesh"; 9 | // console.log(this); 10 | // } 11 | 12 | // sayName(); 13 | -------------------------------------------------------------------------------- /08/02_strings_lyst1064.js: -------------------------------------------------------------------------------- 1 | var name = `hitesh`; 2 | var fullName = `${name} choudhary`; 3 | 4 | console.log(fullName); 5 | console.log(fullName.charAt(0)); 6 | console.log(fullName.endsWith("?")); 7 | console.log(fullName.includes("hitesh")); 8 | console.log(fullName.toUpperCase()); 9 | -------------------------------------------------------------------------------- /08/10_API_lyst8229.js: -------------------------------------------------------------------------------- 1 | fetch("https://api.chucknorris.io/jokes/random") 2 | .then((response) => { 3 | return response.json(); 4 | }) 5 | .then((data) => { 6 | // console.log("DATA is :", data); 7 | var joke = data.value; 8 | console.log("JOKE:", joke); 9 | }) 10 | .catch(); 11 | -------------------------------------------------------------------------------- /03/03_jsContext_lyst5285.js: -------------------------------------------------------------------------------- 1 | // sayHello(); 2 | 3 | // function sayHello() { 4 | // console.log("Hello"); 5 | // } 6 | 7 | if (2 === "2") { 8 | console.log("This is true"); 9 | } 10 | 11 | var myName = "hitesh"; 12 | if (myName === window.myName) { 13 | console.log("This is again a true statement"); 14 | } 15 | -------------------------------------------------------------------------------- /02/06_ConditionalLogin_lyst2886.js: -------------------------------------------------------------------------------- 1 | // Allow user to access course if he is: 2 | // logged in from email 3 | // logged in from Google 4 | // logged in from Facebook 5 | 6 | var email = true; 7 | var facebook = false; 8 | var google = true; 9 | 10 | if (email || facebook || google) { 11 | console.log("Login Success"); 12 | } 13 | -------------------------------------------------------------------------------- /08/08_async_lyst8407.js: -------------------------------------------------------------------------------- 1 | const uno = () => { 2 | console.log("I am One"); 3 | }; 4 | 5 | const dos = () => { 6 | setTimeout(() => { 7 | console.log("Wooohoooo"); 8 | }, 3000); 9 | console.log("I am Two"); 10 | }; 11 | 12 | const tres = () => { 13 | console.log("I am Three"); 14 | }; 15 | 16 | uno(); 17 | dos(); 18 | tres(); 19 | -------------------------------------------------------------------------------- /03/05_scopeChaining_lyst1592.js: -------------------------------------------------------------------------------- 1 | var name = "Hitesh"; 2 | 3 | console.log("Line number 3", name); 4 | 5 | function sayName() { 6 | var name = "Mr. H"; 7 | console.log("Line number 7", name); 8 | sayNameTwo(); 9 | 10 | function sayNameTwo() { 11 | var name = "Mr. HC"; 12 | console.log("Line number 12", name); 13 | } 14 | } 15 | 16 | sayName(); 17 | -------------------------------------------------------------------------------- /04/10_Objects_lyst6054.js: -------------------------------------------------------------------------------- 1 | var user = { 2 | firstName: "Hitesh", 3 | lastName: "Choudhary", 4 | role: "Admin", 5 | loginCount: 32, 6 | facebookSignedIn: true, 7 | }; 8 | 9 | console.log(user.firstName); 10 | console.log(user["lastName"]); 11 | 12 | console.log(user.loginCount); 13 | user.loginCount = 44; 14 | console.log(user.loginCount); 15 | console.table(user); 16 | -------------------------------------------------------------------------------- /04/15_thisAgain_lyst7403.js: -------------------------------------------------------------------------------- 1 | console.log(this); 2 | 3 | var user = { 4 | firstName: "Hitesh", 5 | courseCount: 4, 6 | getCourseCount: function () { 7 | console.log("LINE 7", this); 8 | function sayHello() { 9 | console.log("Hello"); 10 | console.log("LINE 10", this); 11 | } 12 | sayHello(); 13 | }, 14 | }; 15 | 16 | user.getCourseCount(); 17 | -------------------------------------------------------------------------------- /03/01_functions_lyst3526.js: -------------------------------------------------------------------------------- 1 | function sayHello(name) { 2 | console.log("Hello there, Hitesh"); 3 | console.log(`Hello there, ${name}. How are you?`); 4 | } 5 | 6 | // sayHello("hitesh"); 7 | // sayHello("Sammy"); 8 | 9 | function namstey() { 10 | return "Hello in India"; 11 | } 12 | 13 | var greetings = namstey(); 14 | 15 | console.log(greetings); 16 | console.log(namstey()); 17 | -------------------------------------------------------------------------------- /04/13_loopsPartTwo_lyst6138.js: -------------------------------------------------------------------------------- 1 | const myStates = [ 2 | "Rajasthan", 3 | "Delhi", 4 | "Assam", 5 | 1947, 6 | "Tamil Nadu", 7 | "Maharashtra", 8 | ]; 9 | 10 | // var i = 0; 11 | 12 | // for (;;) { 13 | // if (i > 3) break; 14 | // console.log(i); 15 | // i++; 16 | // } 17 | 18 | myStates.forEach((s) => (console.log(s))); 19 | myStates.forEach((s) => console.log(s)); 20 | -------------------------------------------------------------------------------- /02/07_ConditionalSignout_lyst1248.js: -------------------------------------------------------------------------------- 1 | // Show user a signout button if he is authenticated, 2 | // other wise show him option to Login/Signup 3 | 4 | var authenticated = true; 5 | 6 | // if (authenticated) { 7 | // console.log("Show signout button"); 8 | // } else { 9 | // console.log("Show login option"); 10 | // } 11 | 12 | authenticated ? console.log("SignOut Button") : console.log("LOGIN"); 13 | -------------------------------------------------------------------------------- /04/08_arrayPartTwo_lyst7153.js: -------------------------------------------------------------------------------- 1 | var isEven = (element) => { 2 | // if (element % 2 === 0) { 3 | // return true; 4 | // } 5 | // return false; 6 | 7 | return element % 2 === 0; 8 | }; 9 | 10 | // console.log(isEven(2)); 11 | 12 | // var result = [2, 3, 6, 8].every(isEven); 13 | // console.log(result); 14 | 15 | var result = [2, 3, 6, 8].every((e) => (e % 2 === 0)); 16 | console.log(result); 17 | -------------------------------------------------------------------------------- /04/14_loopsPartThree_lyst2770.js: -------------------------------------------------------------------------------- 1 | const names = ["Youtube", "facebook", "Instagram", "Netflix", "Amazon"]; 2 | 3 | // for (const n of names) { 4 | // console.log(n); 5 | // } 6 | 7 | const symbols = { 8 | yt: "Youtube", 9 | ig: "Instagram", 10 | fb: "Facebook", 11 | lco: "LearnCodeOnline.in", 12 | }; 13 | 14 | for (const n in symbols) { 15 | console.log(`Key is: ${n} and value is: ${symbols[n]}`); 16 | } 17 | -------------------------------------------------------------------------------- /02/04_Conditional_lyst5979.js: -------------------------------------------------------------------------------- 1 | var temperature; 2 | 3 | //TODO: GO to google and get the data 4 | 5 | temperature = 49; 6 | 7 | // var result = temperature < 20; 8 | // console.log(result); 9 | 10 | if (temperature < 20) { 11 | console.log("it's very cold outside"); 12 | } 13 | 14 | if (temperature < 30) { 15 | console.log("It's moderate outside"); 16 | } else { 17 | console.log("It's really HOT outside"); 18 | } 19 | -------------------------------------------------------------------------------- /08/04_pickData_lyst5294.js: -------------------------------------------------------------------------------- 1 | // const user = ["hitesh", 3, "admin"]; 2 | // // var role = user[2]; 3 | // // var name = user[0]; 4 | 5 | // var [name, courseCount, role] = user; 6 | 7 | //console.log(role); 8 | 9 | const MyUser = { 10 | name: "hitesh", 11 | courseCount: 5, 12 | role: "admin", 13 | }; 14 | 15 | console.log(MyUser.courseCount); 16 | 17 | const { name, courseCount, role } = MyUser; 18 | console.log(role); 19 | -------------------------------------------------------------------------------- /06/02_ObjectsPartTwo_lyst8077.js: -------------------------------------------------------------------------------- 1 | var User = { 2 | name: "", 3 | getUserName: function () { 4 | console.log(`User name is : ${this.name}`); 5 | }, 6 | }; 7 | 8 | var hitesh = Object.create(User); 9 | console.log(hitesh); 10 | hitesh.name = "hitesh Choudhary"; 11 | hitesh.getUserName(); 12 | 13 | var sam = Object.create(User, { 14 | name: { value: "sammy" }, 15 | courseCount: { value: 3 }, 16 | }); 17 | 18 | sam.getUserName(); 19 | -------------------------------------------------------------------------------- /03/04_hoisting_lyst2895.js: -------------------------------------------------------------------------------- 1 | tipper("80"); 2 | 3 | function tipper(a) { 4 | var bill = parseInt(a); 5 | console.log(bill + 5); 6 | } 7 | 8 | var bigTipper = function (a) { 9 | var bill = parseInt(a); 10 | console.log(bill + 15); 11 | }; 12 | 13 | bigTipper("200"); 14 | 15 | console.log(name); 16 | var name = "hitesh"; 17 | 18 | function sayName() { 19 | var name = "MR. H"; 20 | console.log(name); 21 | } 22 | sayName(); 23 | 24 | console.log(name); 25 | -------------------------------------------------------------------------------- /01/01Variables_lyst6562.js: -------------------------------------------------------------------------------- 1 | var fullName = "Hitesh Choudhary"; 2 | 3 | // how to name variables 4 | 5 | // fullName 6 | // full-name 7 | // full_name 8 | // FullName 9 | 10 | var courseName = "React JS Bootcamp"; 11 | 12 | var isLoggedIn = false; 13 | 14 | var loggedCount = 34; 15 | 16 | // console.log(loggedCount); 17 | // console.log("loggedCount"); 18 | 19 | var paymentMode; 20 | 21 | paymentMode = "Credit Card"; 22 | console.log(paymentMode); 23 | 24 | // var if = 23; 25 | -------------------------------------------------------------------------------- /04/09_filterArray_lyst2301.js: -------------------------------------------------------------------------------- 1 | var testArray = [2, 4, 6, 3, 1, 5, 9, 8]; 2 | 3 | //console.log(testArray.fill("empty")); 4 | 5 | const myNumber = [23, 24, 25, 55, 66, 77, 87, 98]; 6 | 7 | const result = myNumber.filter((num) => num > 55); 8 | 9 | //console.log(result); 10 | 11 | // Yes, Same exercise file 12 | 13 | var users = ["Ted", "Tim", "Ton", "Sam", "Sor", "Sod"]; 14 | 15 | // console.log(users.slice(1)); 16 | users.splice(1, 3, "HI", "BYE"); 17 | // users.splice() 18 | console.log(users); 19 | -------------------------------------------------------------------------------- /06/05_Closure_lyst9236.js: -------------------------------------------------------------------------------- 1 | // function init() { 2 | // var firstName = "hitesh"; 3 | // console.log("I am init"); 4 | 5 | // function sayFirstName() { 6 | // console.log(firstName); 7 | // } 8 | // return sayFirstName; 9 | // } 10 | 11 | // var value = init(); 12 | 13 | // value(); 14 | 15 | function doAddition(x) { 16 | return function (y) { 17 | return x + y; 18 | }; 19 | } 20 | 21 | var add5 = doAddition(4); 22 | console.log(add5(5)); 23 | 24 | console.log(doAddition(5)(5)); 25 | //doAddition()()() //curring 26 | -------------------------------------------------------------------------------- /01/02_Variables-two_lyst6907.js: -------------------------------------------------------------------------------- 1 | const uid = "abc123"; 2 | 3 | var fullName = "Hitesh Choudhary"; 4 | var email = "hitesh@lco.dev"; 5 | var password = "123456"; 6 | var confirmPassword = "123456"; 7 | var courseCount = 0; 8 | var isLoggedInFromGoogle = false; 9 | 10 | // fullname = prompt("Enter your name"); 11 | 12 | console.log(uid); 13 | console.log("Full Name is: ", fullName); 14 | console.log(email); 15 | 16 | console.log(` 17 | With Unique ID: ${uid} 18 | User is : ${fullName} 19 | and his email is: ${email} 20 | and uses the password: ${password} 21 | 22 | `); 23 | -------------------------------------------------------------------------------- /04/12_loops_lyst2766.js: -------------------------------------------------------------------------------- 1 | // for (let i = 0; i <= 10; i++) { 2 | // console.log(i); 3 | // } 4 | 5 | const myStates = [ 6 | "Rajasthan", 7 | "Delhi", 8 | "Assam", 9 | 1947, 10 | "Tamil Nadu", 11 | "Maharashtra", 12 | ]; 13 | 14 | // for (let i = 0; i < myStates.length; i++) { 15 | // if (typeof myStates[i] !== "string") break; 16 | // console.log(myStates[i]); 17 | // } 18 | 19 | // while (i < myStates.length) { 20 | // console.log(myStates[i]); 21 | // i++; 22 | // } 23 | 24 | // let i = 20; 25 | 26 | // do { 27 | // console.log(i); 28 | // i++; 29 | // } while (i < 10); 30 | -------------------------------------------------------------------------------- /08/03_maps_lyst6550.js: -------------------------------------------------------------------------------- 1 | var myMap = new Map(); 2 | 3 | myMap.set(1, "Uno"); 4 | myMap.set(2, "dos"); 5 | myMap.set(3, "Tres"); 6 | myMap.set(4, "Cuatro"); 7 | 8 | console.log(myMap); 9 | 10 | // for (let key of myMap.keys()) { 11 | // console.log(`Key is ${key}`); 12 | // } 13 | 14 | // for (let value of myMap.values()) { 15 | // console.log(`Value is ${value}`); 16 | // } 17 | 18 | for (let [key, value] of myMap) { 19 | console.log(`Key is : ${key} and Value is ${value}`); 20 | } 21 | 22 | myMap.forEach((v, k) => console.log(`${v} and key is ${k}`)); 23 | 24 | myMap.delete(2); 25 | console.log(myMap); 26 | -------------------------------------------------------------------------------- /04/07_array_lyst8270.js: -------------------------------------------------------------------------------- 1 | var countries = ["India", "USA", "Japan", "Russia"]; 2 | 3 | var states = new Array("Rajasthan", "Delhi", "Mumbai", "Assam"); 4 | 5 | //console.log(states[1]); 6 | 7 | //console.log(states.length); 8 | states[0] = "Punjab"; 9 | //console.log(states); 10 | 11 | var user = ["hitesh", "hitesh@lco.dev", 3, 34, true]; 12 | //console.log(user); 13 | 14 | user.pop(); 15 | user.pop(); 16 | //console.log(user); 17 | user.unshift("NEW VALUE"); 18 | //console.log(user); 19 | user.shift(); 20 | console.log(user); 21 | 22 | console.log(user.indexOf("newyy")); 23 | 24 | console.log(Array.from("hitesh")); 25 | -------------------------------------------------------------------------------- /01/03_Operators_lyst3638.js: -------------------------------------------------------------------------------- 1 | // D = (L - S)/L * 100 2 | 3 | // a + ((b * c) / d) * e 4 | 5 | var sellingPrice = 199; 6 | var listingPrice = 799; 7 | 8 | var discountPercent = ((listingPrice - sellingPrice) / listingPrice) * 100; 9 | 10 | console.log("Discount percentage is :" + discountPercent); 11 | 12 | displayDiscountPercentage = Math.round(discountPercent); 13 | 14 | console.log(displayDiscountPercentage + "% off"); 15 | 16 | var result = listingPrice > sellingPrice; 17 | 18 | console.log(typeof result); 19 | 20 | // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence 21 | -------------------------------------------------------------------------------- /01/03_Operators_lyst7877.js: -------------------------------------------------------------------------------- 1 | // D = (L - S)/L * 100 2 | 3 | // a + ((b * c) / d) * e 4 | 5 | var sellingPrice = 199; 6 | var listingPrice = 799; 7 | 8 | var discountPercent = ((listingPrice - sellingPrice) / listingPrice) * 100; 9 | 10 | console.log("Discount percentage is :" + discountPercent); 11 | 12 | displayDiscountPercentage = Math.round(discountPercent); 13 | 14 | console.log(displayDiscountPercentage + "% off"); 15 | 16 | var result = listingPrice > sellingPrice; 17 | 18 | console.log(typeof result); 19 | 20 | // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence 21 | -------------------------------------------------------------------------------- /08/05_spread_lyst9584.js: -------------------------------------------------------------------------------- 1 | // var returnedValue = Math.max(2, 5, 7, 4, 2, 8); 2 | // console.log(returnedValue); 3 | 4 | // var myObj = {}; 5 | 6 | // Object.assign(myObj, { a: 1, b: 2, c: 3 }, { z: 9, y: 8, x: 7 }); 7 | // console.log(myObj); 8 | 9 | function sumOne(a, b) { 10 | return a + b; 11 | } 12 | 13 | var myA = [5, 4]; 14 | //console.log(sumOne(...myA)); // spread Op 15 | 16 | function sumTwo(a, b, ...args) { 17 | console.log(args); 18 | let multi = a * b; 19 | let sum = 0; 20 | for (const arg of args) { 21 | sum += arg; 22 | } 23 | return [sum, multi]; 24 | } 25 | 26 | console.log(sumTwo(2, 3, 1, 1, 1)); 27 | -------------------------------------------------------------------------------- /04/11_objectsPartTwo_lyst3320.js: -------------------------------------------------------------------------------- 1 | var user = { 2 | firstName: "Hitesh", 3 | lastName: "Choudhary", 4 | role: "Admin", 5 | loginCount: 32, 6 | facebookSignedIn: true, 7 | courseList: [], 8 | buyCourse: function (courseName) { 9 | this.courseList.push(courseName); 10 | }, 11 | getCourseCount: function () { 12 | return `${this.firstName} is enrolled in total of ${this.courseList.length} courses`; 13 | }, 14 | }; 15 | 16 | var courseList = true; 17 | console.log(user.firstName); 18 | console.log(user.getCourseCount()); 19 | user.buyCourse("React JS course"); 20 | user.buyCourse("Angular course"); 21 | console.log(user.getCourseCount()); 22 | -------------------------------------------------------------------------------- /08/09_Promise_lyst9698.js: -------------------------------------------------------------------------------- 1 | const uno = () => { 2 | return "I am One"; 3 | }; 4 | 5 | // const dos = () => { 6 | // setTimeout(() => { 7 | // return "I am two"; 8 | // }, 3000); 9 | // }; 10 | 11 | const dos = () => { 12 | return new Promise((resolve, reject) => { 13 | setTimeout(() => { 14 | resolve("I am two"); 15 | }, 3000); 16 | }); 17 | }; 18 | 19 | const tres = () => { 20 | return "I am Three"; 21 | }; 22 | 23 | const callMe = async () => { 24 | let valOne = uno(); 25 | console.log(valOne); 26 | 27 | let valTwo = await dos(); 28 | console.log(valTwo); 29 | 30 | let valThree = tres(); 31 | console.log(valThree); 32 | }; 33 | 34 | callMe(); 35 | -------------------------------------------------------------------------------- /06/01_Objects_lyst2840.js: -------------------------------------------------------------------------------- 1 | var User = function (firstName, courseCount) { 2 | this.firstName = firstName; 3 | this.courseCount = courseCount; 4 | this.getCourseCount = function () { 5 | console.log(`Course count is: ${this.courseCount}`); 6 | }; 7 | }; 8 | 9 | User.prototype.getFirstname = function () { 10 | console.log(`Your firstname is : ${this.firstName}`); 11 | }; 12 | 13 | var hitesh = new User("hitesh", 2); 14 | hitesh.getCourseCount(); 15 | 16 | if (hitesh.hasOwnProperty("firstName")) { 17 | hitesh.getFirstname(); 18 | } 19 | 20 | //console.log(hitesh); 21 | 22 | var sam = new User("Sam", 1); 23 | sam.getCourseCount(); 24 | sam.getFirstname(); 25 | //console.log(sam); 26 | -------------------------------------------------------------------------------- /06/06_thisBinding_lyst7219.js: -------------------------------------------------------------------------------- 1 | const hitesh = { 2 | firstName: "Hitesh", 3 | lastName: "Choudhary", 4 | role: "Admin", 5 | courseCount: 3, 6 | getInfo: function () { 7 | console.log(` 8 | First name is ${this.firstName} 9 | Last name is ${this.lastName} 10 | His role is ${this.role} 11 | and he is studying ${this.courseCount} courses 12 | `); 13 | }, 14 | }; 15 | 16 | const dj = { 17 | firstName: "Rock", 18 | lastName: "DJ", 19 | role: "Sub-Admin", 20 | courseCount: 4, 21 | }; 22 | 23 | // hitesh.getInfo(); 24 | // dj.getInfo(); 25 | 26 | // var djInfo = hitesh.getInfo.bind(dj); 27 | // djInfo(); 28 | 29 | hitesh.getInfo.call(dj); 30 | -------------------------------------------------------------------------------- /02/05_ConditionalPurchase_lyst2042.js: -------------------------------------------------------------------------------- 1 | // User is only allowed to make a purchase when he is: 2 | // logged in 3 | // email verified 4 | // cardInfo - valid 5 | // If any one is missing, stop purchase 6 | 7 | var isLoggedIn = true; 8 | var isEmailVerified = false; 9 | var cardInfo = true; 10 | 11 | // if (isLoggedIn) { 12 | // console.log("Logged IN Success"); 13 | // if (isEmailVerified) { 14 | // console.log("Email is verified"); 15 | // if (cardInfo) { 16 | // console.log("You can make a purchase"); 17 | // } 18 | // } 19 | // } 20 | 21 | if (isLoggedIn && isEmailVerified && cardInfo) { 22 | console.log("Allow user to make a purchase"); 23 | } else { 24 | console.log("You are NOT allowed to do that"); 25 | } 26 | -------------------------------------------------------------------------------- /02/08_ConditionalRoles_lyst4025.js: -------------------------------------------------------------------------------- 1 | // Create an application with following roles: 2 | // admin - gets full access 3 | // subadmin - gets access to create/delete courses 4 | // testprep - gets access to create/delete tests 5 | // user - gets access to consume content 6 | 7 | var user = "admin"; 8 | 9 | switch (user) { 10 | case "admin": 11 | console.log("You get full access"); 12 | break; 13 | case "subadmin": 14 | console.log("gets access to create/delete courses"); 15 | break; 16 | case "testprep": 17 | console.log("gets access to create/delete tests"); 18 | break; 19 | case "user": 20 | console.log("gets access to consume content"); 21 | break; 22 | default: 23 | console.log("Trial user"); 24 | 25 | break; 26 | } 27 | -------------------------------------------------------------------------------- /10/jsSort_lyst7387.js: -------------------------------------------------------------------------------- 1 | // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort 2 | 3 | // https://docs.oracle.com/cd/B10501_01/server.920/a96529/appb.htm#951505 4 | 5 | // https://developer.apple.com/documentation/swift/unicode/scalar/properties/3081577-isemoji 6 | 7 | // [6, -2, 2, -7].sort(); 8 | 9 | function mySort(a, b) { 10 | if (a > b) { 11 | return 1; 12 | } else if (b > a) { 13 | return -1; 14 | } else { 15 | return 0; 16 | } 17 | } 18 | 19 | function batmanGameOrder(a, b) { 20 | var batman = [ 21 | "Arkham Origins", 22 | "Arkham Origins Blackgate", 23 | "Assault On Arkham", 24 | "Arkham Asylum", 25 | "Arkham City", 26 | "Arkham Knight", 27 | ]; 28 | 29 | return batman.indexOf(a) - batman.indexOf(b); 30 | } 31 | 32 | var games = [ 33 | "Arkham Knight", 34 | "Arkham Asylum", 35 | "Arkham Origins", 36 | "Arkham Origins Blackgate", 37 | ]; 38 | 39 | games.sort(batmanGameOrder); 40 | -------------------------------------------------------------------------------- /03/02_userRoleFunction_lyst4182.js: -------------------------------------------------------------------------------- 1 | /* 2 | Define a function that can answer the role of a user. 3 | A user can be on following roles: 4 | admin - with all access 5 | subadmin - with acccess to create/delete courses 6 | testprep - with access to create/delete tests 7 | user - consume all content 8 | other - trial user. 9 | 10 | Input: getUserRole(name, role) 11 | */ 12 | 13 | var getUserRole = function (name, role) { 14 | switch (role) { 15 | case "admin": 16 | return `${name} is admin with all access`; 17 | break; // this is not necessary 18 | case "subadmin": 19 | return `${name} is sub-admin with access to create and delete courses`; 20 | break; 21 | case "testprep": 22 | return `${name} is a test prep with access to create and delete tests`; 23 | break; 24 | case "user": 25 | return `${name} is a user to consume content`; 26 | break; 27 | 28 | default: 29 | return `${name} is a trial user`; 30 | break; 31 | } 32 | }; 33 | 34 | console.log(getUserRole("hitesh", "testprep")); 35 | 36 | var getRole = getUserRole("sammy", "user"); 37 | 38 | console.log(getRole); 39 | --------------------------------------------------------------------------------