├── day-03 ├── q8 │ └── main.ts ├── q7 │ ├── main.ts │ └── main.js ├── q9 │ ├── main.js │ └── main.ts └── README.md ├── day-01 ├── q1 │ └── main.ts ├── q2 │ ├── main.js │ └── main.ts ├── q3 │ ├── main.js │ └── main.ts └── README.md ├── day-44 ├── q132 │ ├── Calculator.ts │ ├── utils.ts │ └── main.ts ├── q130 │ ├── mathFunction.ts │ ├── main.ts │ ├── mathFunction.js │ └── main.js ├── q131 │ ├── main.ts │ ├── Person.ts │ ├── main.js │ └── Person.js └── README.md ├── day-02 ├── q4 │ ├── main.js │ └── main.ts ├── q5 │ ├── main.ts │ └── main.js ├── q6 │ ├── main.js │ └── main.ts └── README.md ├── day-04 ├── q11 │ ├── main.js │ └── main.ts ├── q12 │ ├── main.ts │ └── main.js ├── q10 │ ├── main.js │ └── main.ts └── README.md ├── day-07 ├── q20 │ ├── main.js │ └── main.ts ├── q19 │ ├── main.ts │ └── main.js ├── q21 │ ├── main.js │ └── main.ts └── README.md ├── day-11 ├── q31 │ ├── main.js │ └── main.ts ├── q33 │ ├── main.ts │ └── main.js └── q32 │ ├── main.js │ └── main.ts ├── day-63 ├── TS-Types │ ├── 03-Any-Type.ts │ ├── 02-Dynamic-Type-Determination.ts │ └── 01-Type-Annotations.ts └── README.md ├── day-92 └── README.md ├── day-100 └── README.md ├── day-95 └── README.md ├── day-12 ├── q34 │ ├── main.ts │ └── main.js ├── q36 │ ├── main.js │ └── main.ts └── q35 │ ├── main.ts │ └── main.js ├── day-90 └── README.md ├── day-96 └── README.md ├── day-99 └── README.md ├── day-05 ├── q13 │ ├── main.ts │ └── main.js ├── q14 │ ├── main.ts │ └── main.js └── q15 │ ├── main.ts │ └── main.js ├── day-16 ├── q48 │ ├── main.ts │ └── main.js ├── q46 │ ├── main.ts │ └── main.js ├── q47 │ ├── main.ts │ └── main.js └── README.md ├── day-93 └── README.md ├── day-34 ├── q100 │ ├── main.js │ └── main.ts ├── q102 │ ├── main.js │ └── main.ts ├── README.md └── q101 │ ├── main.js │ └── main.ts ├── day-51 └── README.md ├── day-89 └── README.md ├── day-98 └── README.md ├── day-97 └── README.md ├── day-91 └── README.md ├── day-94 └── README.md ├── day-13 ├── q38 │ ├── main.ts │ └── main.js ├── q39 │ ├── main.js │ └── main.ts └── q37 │ ├── main.ts │ └── main.js ├── day-14 ├── q41 │ ├── main.js │ └── main.ts ├── q40 │ ├── main.js │ └── main.ts └── q42 │ ├── main.js │ └── main.ts ├── day-40 ├── q118 │ ├── main.ts │ └── main.js ├── q119 │ ├── main.js │ └── main.ts ├── README.md └── q120 │ ├── main.ts │ └── main.js ├── day-74 ├── README.md └── TS-debugging │ └── 01-debugging.ts ├── day-78 └── README.md ├── day-65 ├── TS-Function │ ├── 04-Arrow-Function.ts │ ├── 05-Anonymous-Function.ts │ ├── 03-Function-Rest-Parameter.ts │ ├── 06-void-&-never.ts │ ├── 01-Type-Annotations-With-Function.ts │ └── 02-Optional-And-Default-Parameter.ts └── README.md ├── day-08 ├── q22 │ ├── main.js │ └── main.ts └── q23 │ ├── main.js │ └── main.ts ├── day-69 ├── README.md └── TS-Enums │ └── 01-Enums.ts ├── day-73 ├── TS-Type-Assertions │ └── 01-Type-Assertions.ts └── README.md ├── day-77 └── README.md ├── day-50 ├── q148 │ ├── main.ts │ └── main.js ├── q149 │ ├── main.js │ └── main.ts ├── README.md └── q150 │ ├── main.ts │ └── main.js ├── day-54 └── README.md ├── day-72 ├── README.md └── TS-Generics │ ├── 01-Generics-Intro.ts │ └── 03-Generics-Classes.ts ├── day-68 ├── README.md └── TS-Tuple │ └── 01-Tuple.ts ├── day-70 ├── README.md └── TS-Interface │ ├── 01-Interface-Intro.ts │ ├── 04-HTMLImageElement.ts │ ├── 02-Interface-Method-And-Parameters.ts │ └── 03-ReOpen-The-Interface-And-Use-Cases.ts ├── day-66 ├── TS-Type-System-Concepts │ ├── 02-Literal-Types.ts │ ├── 01-Union-Types.ts │ ├── 05-Intersection-Type.ts │ ├── 03-Nullable-Types.ts │ └── 04-Type-Alias.ts └── README.md ├── day-71 ├── README.md └── TS-Class │ └── 01-Class-Type-Annotations.ts ├── day-86 └── README.md ├── day-67 ├── README.md └── TS-Array │ ├── 02-Type-Annotations-With-Multidimensional-Arrays.ts │ └── 01-Type-Annotations-With-Arrays.ts ├── day-64 ├── README.md └── TS-Object │ └── 01-Type-Annotations-With-Objects.ts ├── day-15 ├── q44 │ ├── main.ts │ └── main.js ├── q45 │ ├── main.ts │ └── main.js └── q43 │ ├── main.js │ └── main.ts ├── day-56 └── README.md ├── day-75 └── README.md ├── day-76 └── README.md ├── day-87 └── README.md ├── day-59 └── README.md ├── day-60 └── README.md ├── day-10 ├── q29 │ ├── main.js │ └── main.ts ├── q30 │ ├── main.ts │ └── main.js └── q28 │ ├── main.ts │ └── main.js ├── day-55 └── README.md ├── day-80 └── README.md ├── day-57 └── README.md ├── day-85 └── README.md ├── day-41 ├── q121 │ ├── main.ts │ └── main.js ├── README.md ├── q122 │ ├── main.js │ └── main.ts └── q123 │ ├── main.ts │ └── main.js ├── day-47 ├── q140 │ ├── main.js │ └── main.ts ├── README.md ├── q139 │ ├── main.js │ └── main.ts └── q141 │ └── main.ts ├── day-88 └── README.md ├── day-37 ├── q109 │ ├── main.js │ └── main.ts ├── README.md ├── q110 │ ├── main.ts │ └── main.js └── q111 │ ├── main.ts │ └── main.js ├── day-61 └── README.md ├── day-09 ├── q25 │ ├── main.js │ └── main.ts └── q26 │ ├── main.ts │ └── main.js ├── day-45 ├── README.md ├── q134 │ ├── main.js │ └── main.ts ├── q133 │ ├── main.js │ └── main.ts └── q135 │ ├── main.js │ └── main.ts ├── day-84 └── README.md ├── day-31 ├── q91 │ ├── main.js │ └── main.ts ├── README.md ├── q92 │ ├── main.js │ └── main.ts └── q93 │ ├── main.js │ └── main.ts ├── day-49 ├── README.md ├── q146 │ ├── main.js │ └── main.ts ├── q145 │ ├── main.js │ └── main.ts └── q147 │ ├── main.js │ └── main.ts ├── day-58 └── README.md ├── day-82 └── README.md ├── day-83 └── README.md ├── day-22 ├── q65 │ ├── main.js │ └── main.ts ├── q66 │ ├── main.js │ └── main.ts ├── q64 │ ├── main.js │ └── main.ts └── README.md ├── day-17 ├── q50 │ ├── main.js │ └── main.ts ├── q49 │ ├── main.ts │ └── main.js ├── q51 │ ├── main.js │ └── main.ts └── README.md ├── day-18 ├── q52 │ ├── main.ts │ └── main.js ├── q54 │ ├── main.js │ └── main.ts ├── q53 │ ├── main.ts │ └── main.js └── README.md ├── day-35 ├── README.md ├── q105 │ ├── main.js │ └── main.ts ├── q103 │ ├── main.js │ └── main.ts └── q104 │ ├── main.js │ └── main.ts ├── day-46 ├── q136 │ ├── main.ts │ └── main.js ├── README.md ├── q137 │ ├── main.ts │ └── main.js └── q138 │ ├── main.js │ └── main.ts ├── day-21 ├── q62 │ ├── main.js │ └── main.ts ├── q61 │ ├── main.ts │ └── main.js ├── q63 │ ├── main.js │ └── main.ts └── README.md ├── day-27 ├── q79 │ ├── main.js │ └── main.ts ├── q80 │ ├── main.js │ └── main.ts ├── q81 │ ├── main.ts │ └── main.js └── README.md ├── day-48 ├── README.md ├── q142 │ ├── main.ts │ └── main.js ├── q144 │ ├── main.js │ └── main.ts └── q143 │ ├── main.ts │ └── main.js ├── day-19 ├── q55 │ ├── main.js │ └── main.ts ├── q57 │ ├── main.js │ └── main.ts ├── README.md └── q56 │ ├── main.js │ └── main.ts ├── day-30 ├── q89 │ ├── main.js │ └── main.ts ├── q88 │ ├── main.js │ └── main.ts ├── q90 │ ├── main.js │ └── main.ts └── README.md ├── day-33 ├── README.md ├── q98 │ ├── main.js │ └── main.ts ├── q97 │ ├── main.ts │ └── main.js └── q99 │ ├── main.js │ └── main.ts ├── day-36 ├── README.md ├── q106 │ ├── main.js │ └── main.ts ├── q107 │ ├── main.js │ └── main.ts └── q108 │ ├── main.js │ └── main.ts ├── day-62 └── README.md ├── day-79 └── README.md ├── day-43 ├── README.md ├── q128 │ ├── main.ts │ └── main.js ├── q127 │ ├── main.js │ └── main.ts └── q129 │ ├── main.ts │ └── main.js ├── day-26 ├── q76 │ ├── main.js │ └── main.ts ├── q77 │ ├── main.ts │ └── main.js ├── q78 │ ├── main.js │ └── main.ts └── README.md ├── day-28 ├── q82 │ ├── main.js │ └── main.ts ├── README.md ├── q83 │ ├── main.js │ └── main.ts └── q84 │ ├── main.js │ └── main.ts ├── day-38 ├── q112 │ ├── main.js │ └── main.ts ├── README.md └── q114 │ ├── main.js │ └── main.ts ├── day-81 └── README.md ├── day-23 ├── q68 │ ├── main.js │ └── main.ts ├── q67 │ ├── main.js │ └── main.ts ├── README.md └── q69 │ ├── main.js │ └── main.ts ├── day-29 ├── q85 │ ├── main.js │ └── main.ts ├── q86 │ ├── main.js │ └── main.ts ├── q87 │ ├── main.js │ └── main.ts └── README.md ├── day-32 ├── q94 │ ├── main.js │ └── main.ts ├── README.md ├── q95 │ ├── main.js │ └── main.ts └── q96 │ ├── main.js │ └── main.ts ├── day-39 ├── README.md ├── q117 │ ├── main.ts │ └── main.js ├── q116 │ ├── main.ts │ └── main.js └── q115 │ └── main.ts ├── day-42 ├── README.md ├── q124 │ ├── main.js │ └── main.ts ├── q125 │ ├── main.ts │ └── main.js └── q126 │ ├── main.ts │ └── main.js ├── day-06 ├── q16 │ ├── main.js │ └── main.ts ├── q18 │ └── main.ts └── q17 │ └── main.ts ├── day-20 ├── README.md ├── q59 │ ├── main.js │ └── main.ts ├── q58 │ ├── main.ts │ └── main.js └── q60 │ ├── main.ts │ └── main.js ├── day-52 └── README.md ├── day-24 ├── q70 │ ├── main.ts │ └── main.js ├── q71 │ ├── main.ts │ └── main.js ├── README.md └── q72 │ ├── main.ts │ └── main.js ├── day-25 ├── q73 │ ├── main.ts │ └── main.js ├── q74 │ ├── main.js │ └── main.ts ├── README.md └── q75 │ ├── main.js │ └── main.ts └── day-53 └── README.md /day-03/q8/main.ts: -------------------------------------------------------------------------------- 1 | // (Refer to the answer for Question 7, as it serves the same purpose.) -------------------------------------------------------------------------------- /day-01/q1/main.ts: -------------------------------------------------------------------------------- 1 | // Question 1: Install Node.js, TypeScript and VS Code on your computer/Laptop. -------------------------------------------------------------------------------- /day-44/q132/Calculator.ts: -------------------------------------------------------------------------------- 1 | export default class Calculator { 2 | // Class definition 3 | } 4 | -------------------------------------------------------------------------------- /day-02/q4/main.js: -------------------------------------------------------------------------------- 1 | console.log('Albert Einstein once said, “A person who never made a mistake never tried anything new.”'); 2 | -------------------------------------------------------------------------------- /day-02/q4/main.ts: -------------------------------------------------------------------------------- 1 | console.log('Albert Einstein once said, “A person who never made a mistake never tried anything new.”'); 2 | -------------------------------------------------------------------------------- /day-04/q11/main.js: -------------------------------------------------------------------------------- 1 | var names = ["Alice", "Bob", "Charlie"]; 2 | for (var i = 0; i < names.length; i++) { 3 | console.log(names[i]); 4 | } 5 | -------------------------------------------------------------------------------- /day-04/q11/main.ts: -------------------------------------------------------------------------------- 1 | let names: string[] = ["Alice", "Bob", "Charlie"]; 2 | for (let i = 0; i < names.length; i++) { 3 | console.log(names[i]); 4 | } -------------------------------------------------------------------------------- /day-07/q20/main.js: -------------------------------------------------------------------------------- 1 | var countries = ["Japan", "Canada", "New Zealand", "Iceland", "Switzerland"]; 2 | console.log("Countries I'd like to visit:", countries); 3 | -------------------------------------------------------------------------------- /day-03/q7/main.ts: -------------------------------------------------------------------------------- 1 | console.log(5 + 3); // Addition 2 | console.log(10 - 2); // Subtraction 3 | console.log(4 * 2); // Multiplication 4 | console.log(16 / 2); // Division -------------------------------------------------------------------------------- /day-07/q20/main.ts: -------------------------------------------------------------------------------- 1 | let countries: string[] = ["Japan", "Canada", "New Zealand", "Iceland", "Switzerland"]; 2 | console.log("Countries I'd like to visit:", countries); -------------------------------------------------------------------------------- /day-03/q7/main.js: -------------------------------------------------------------------------------- 1 | console.log(5 + 3); // Addition 2 | console.log(10 - 2); // Subtraction 3 | console.log(4 * 2); // Multiplication 4 | console.log(16 / 2); // Division 5 | -------------------------------------------------------------------------------- /day-11/q31/main.js: -------------------------------------------------------------------------------- 1 | var usernames = []; 2 | if (usernames.length === 0) { 3 | console.log("We need to find some users!"); 4 | } 5 | else { 6 | // Greet Users 7 | } 8 | -------------------------------------------------------------------------------- /day-44/q132/utils.ts: -------------------------------------------------------------------------------- 1 | // Named export example in file: utils.ts 2 | export const utilOne = () => { 3 | /*...*/ 4 | }; 5 | export const utilTwo = () => { 6 | /*...*/ 7 | }; 8 | -------------------------------------------------------------------------------- /day-63/TS-Types/03-Any-Type.ts: -------------------------------------------------------------------------------- 1 | /************ 2 | * ANY TYPE * 3 | ************/ 4 | 5 | let myVariable: any = 42; 6 | myVariable = "Hello, TypeScript"; 7 | console.log(myVariable) -------------------------------------------------------------------------------- /day-01/q2/main.js: -------------------------------------------------------------------------------- 1 | var myName = "Asharib"; // This saves the name 2 | console.log("Hello ".concat(myName, ", would you like to learn some TypeScript today?")); // This shows the message 3 | -------------------------------------------------------------------------------- /day-01/q2/main.ts: -------------------------------------------------------------------------------- 1 | let myName: string = "Asharib"; // This saves the name 2 | 3 | console.log(`Hello ${myName}, would you like to learn some TypeScript today?`); // This shows the message -------------------------------------------------------------------------------- /day-44/q130/mathFunction.ts: -------------------------------------------------------------------------------- 1 | // In file: mathFunctions.ts 2 | export const add = (a: number, b: number): number => a + b; 3 | // This line exports an add function from mathFunctions.ts 4 | -------------------------------------------------------------------------------- /day-04/q12/main.ts: -------------------------------------------------------------------------------- 1 | let names: string[] = ["Alice", "Bob", "Charlie"]; 2 | for (let name of names) { 3 | console.log(`Hello ${name}, would you like to learn some TypeScript today?`); 4 | } -------------------------------------------------------------------------------- /day-04/q10/main.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /day-92/README.md: -------------------------------------------------------------------------------- 1 | # Day-92 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-92 Task:** 4 | 5 | Today's task is to learn about: 6 | 7 | - [Streaming](https://nextjs.org/learn/dashboard-app/streaming) -------------------------------------------------------------------------------- /day-03/q9/main.js: -------------------------------------------------------------------------------- 1 | var favoriteNumber = 8; // This saves your favorite number 2 | console.log("My favorite number is ".concat(favoriteNumber, ".")); // This shows the message with your favorite number 3 | -------------------------------------------------------------------------------- /day-03/q9/main.ts: -------------------------------------------------------------------------------- 1 | let favoriteNumber: number = 8; // This saves your favorite number 2 | console.log(`My favorite number is ${favoriteNumber}.`); // This shows the message with your favorite number 3 | -------------------------------------------------------------------------------- /day-07/q19/main.ts: -------------------------------------------------------------------------------- 1 | let guests: string[] = ["Albert Einstein", "Marie Curie", "Leonardo da Vinci", "Isaac Newton", "Charles Darwin"]; 2 | console.log(`I am inviting ${guests.length} people to dinner.`); -------------------------------------------------------------------------------- /day-100/README.md: -------------------------------------------------------------------------------- 1 | # Day-100 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-100 Task:** 4 | 5 | Today's task is to learn about: 6 | 7 | - [Next Steps](https://nextjs.org/learn/dashboard-app/next-steps)! -------------------------------------------------------------------------------- /day-95/README.md: -------------------------------------------------------------------------------- 1 | # Day-95 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-95 Task:** 4 | 5 | Today's task is to learn about: 6 | 7 | [Mutating Data](https://nextjs.org/learn/dashboard-app/mutating-data) -------------------------------------------------------------------------------- /day-04/q10/main.ts: -------------------------------------------------------------------------------- 1 | // Asharib, 2024-03-05 2 | // This program prints a personal message. 3 | let myName: string = "Asharib"; 4 | console.log(`Hello ${myName}, would you like to learn some TypeScript today?`); -------------------------------------------------------------------------------- /day-07/q19/main.js: -------------------------------------------------------------------------------- 1 | var guests = ["Albert Einstein", "Marie Curie", "Leonardo da Vinci", "Isaac Newton", "Charles Darwin"]; 2 | console.log("I am inviting ".concat(guests.length, " people to dinner.")); 3 | -------------------------------------------------------------------------------- /day-12/q34/main.ts: -------------------------------------------------------------------------------- 1 | let pizzas: string[] = ["pepperoni", "margherita", "hawaiian"]; 2 | 3 | pizzas.forEach(pizza => { 4 | console.log(`I like ${pizza} pizza.`); 5 | }); 6 | console.log("I really love pizza!"); -------------------------------------------------------------------------------- /day-90/README.md: -------------------------------------------------------------------------------- 1 | # Day-90 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-90 Task:** 4 | 5 | Today's task is to learn about: 6 | 7 | - [Fetching Data](https://nextjs.org/learn/dashboard-app/fetching-data) -------------------------------------------------------------------------------- /day-96/README.md: -------------------------------------------------------------------------------- 1 | # Day-96 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-96 Task:** 4 | 5 | Today's task is to learn about: 6 | 7 | [Handling Errors](https://nextjs.org/learn/dashboard-app/error-handling) -------------------------------------------------------------------------------- /day-99/README.md: -------------------------------------------------------------------------------- 1 | # Day-99 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-99 Task:** 4 | 5 | Today's task is to learn about: 6 | 7 | [Adding Metadata](https://nextjs.org/learn/dashboard-app/adding-metadata) -------------------------------------------------------------------------------- /day-02/q5/main.ts: -------------------------------------------------------------------------------- 1 | let famous_person: string = "Albert Einstein"; 2 | let message: string = `${famous_person} once said, “A person who never made a mistake never tried anything new.”`; 3 | 4 | console.log(message); -------------------------------------------------------------------------------- /day-05/q13/main.ts: -------------------------------------------------------------------------------- 1 | let transports: string[] = ["Honda motorcycle", "Tesla car", "Bianchi bicycle"]; 2 | 3 | transports.forEach(transport => { 4 | console.log(`I would like to own a ${transport}.`); 5 | }); -------------------------------------------------------------------------------- /day-05/q14/main.ts: -------------------------------------------------------------------------------- 1 | let guests: string[] = ["Albert Einstein", "Marie Curie", "Nikola Tesla"]; 2 | 3 | guests.forEach(guest => { 4 | console.log(`Dear ${guest}, would you like to join me for dinner?`); 5 | }); -------------------------------------------------------------------------------- /day-16/q48/main.ts: -------------------------------------------------------------------------------- 1 | let pricesSet1 = [1200, 1500, 1100]; 2 | let pricesSet2 = [1000, 1300, 1600]; 3 | let combinedPrices = [...pricesSet1, ...pricesSet2].sort((a, b) => a - b); 4 | console.log(combinedPrices); 5 | -------------------------------------------------------------------------------- /day-02/q5/main.js: -------------------------------------------------------------------------------- 1 | var famous_person = "Albert Einstein"; 2 | var message = "".concat(famous_person, " once said, \u201CA person who never made a mistake never tried anything new.\u201D"); 3 | console.log(message); 4 | -------------------------------------------------------------------------------- /day-05/q13/main.js: -------------------------------------------------------------------------------- 1 | var transports = ["Honda motorcycle", "Tesla car", "Bianchi bicycle"]; 2 | transports.forEach(function (transport) { 3 | console.log("I would like to own a ".concat(transport, ".")); 4 | }); 5 | -------------------------------------------------------------------------------- /day-02/q6/main.js: -------------------------------------------------------------------------------- 1 | var myName = "\t\n Asharib \t\n"; // This saves the name with whitespace 2 | console.log(myName); // Shows the name with whitespace 3 | console.log(myName.trim()); // Shows the name without whitespace 4 | -------------------------------------------------------------------------------- /day-05/q14/main.js: -------------------------------------------------------------------------------- 1 | var guests = ["Albert Einstein", "Marie Curie", "Nikola Tesla"]; 2 | guests.forEach(function (guest) { 3 | console.log("Dear ".concat(guest, ", would you like to join me for dinner?")); 4 | }); 5 | -------------------------------------------------------------------------------- /day-12/q34/main.js: -------------------------------------------------------------------------------- 1 | var pizzas = ["pepperoni", "margherita", "hawaiian"]; 2 | pizzas.forEach(function (pizza) { 3 | console.log("I like ".concat(pizza, " pizza.")); 4 | }); 5 | console.log("I really love pizza!"); 6 | -------------------------------------------------------------------------------- /day-12/q36/main.js: -------------------------------------------------------------------------------- 1 | function make_shirt(size, message) { 2 | console.log("Making a ".concat(size, " t-shirt with the message \"").concat(message, "\" printed on it")); 3 | } 4 | make_shirt("medium", "Code is Life"); 5 | -------------------------------------------------------------------------------- /day-93/README.md: -------------------------------------------------------------------------------- 1 | # Day-93 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-93 Task:** 4 | 5 | Today's task is to learn about: 6 | 7 | - [Partial Prerendering](https://nextjs.org/learn/dashboard-app/partial-prerendering) 8 | -------------------------------------------------------------------------------- /day-34/q100/main.js: -------------------------------------------------------------------------------- 1 | // Finds the square root of 144 2 | var squareRoot = Math.sqrt(144); 3 | console.log("The square root of 144 is ".concat(squareRoot, ".")); 4 | // This line will show that the square root of 144 is 12. 5 | -------------------------------------------------------------------------------- /day-51/README.md: -------------------------------------------------------------------------------- 1 | # Day-51 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-51 Task:** 4 | 5 | Read the following article: 6 | [Top 10 Programming Tips For Beginners](https://www.geeksforgeeks.org/programming-tips-for-beginners/) -------------------------------------------------------------------------------- /day-63/TS-Types/02-Dynamic-Type-Determination.ts: -------------------------------------------------------------------------------- 1 | /****************************** 2 | * DYNAMIC TYPE DETERMINATION * 3 | ******************************/ 4 | 5 | let greeting = "Hello, world!"; 6 | console.log(greeting); 7 | -------------------------------------------------------------------------------- /day-89/README.md: -------------------------------------------------------------------------------- 1 | # Day-89 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-89 Task:** 4 | 5 | Today's task is to learn about: 6 | 7 | - [Setting Up Your Database](https://nextjs.org/learn/dashboard-app/setting-up-your-database) -------------------------------------------------------------------------------- /day-98/README.md: -------------------------------------------------------------------------------- 1 | # Day-98 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-98 Task:** 4 | 5 | Today's task is to learn about: 6 | 7 | - [Adding Authentication](https://nextjs.org/learn/dashboard-app/adding-authentication) 8 | -------------------------------------------------------------------------------- /day-02/q6/main.ts: -------------------------------------------------------------------------------- 1 | let myName: string = "\t\n Asharib \t\n"; // This saves the name with whitespace 2 | 3 | console.log(myName); // Shows the name with whitespace 4 | console.log(myName.trim()); // Shows the name without whitespace -------------------------------------------------------------------------------- /day-34/q100/main.ts: -------------------------------------------------------------------------------- 1 | // Finds the square root of 144 2 | const squareRoot: number = Math.sqrt(144); 3 | 4 | console.log(`The square root of 144 is ${squareRoot}.`); 5 | // This line will show that the square root of 144 is 12. 6 | -------------------------------------------------------------------------------- /day-97/README.md: -------------------------------------------------------------------------------- 1 | # Day-97 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-97 Task:** 4 | 5 | Today's task is to learn about: 6 | 7 | - [Improving Accessibility](https://nextjs.org/learn/dashboard-app/improving-accessibility) 8 | -------------------------------------------------------------------------------- /day-12/q36/main.ts: -------------------------------------------------------------------------------- 1 | function make_shirt(size: string, message: string) { 2 | console.log( 3 | `Making a ${size} t-shirt with the message "${message}" printed on it` 4 | ); 5 | } 6 | 7 | make_shirt("medium", "Code is Life"); 8 | -------------------------------------------------------------------------------- /day-91/README.md: -------------------------------------------------------------------------------- 1 | # Day-91 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-91 Task:** 4 | 5 | Today's task is to learn about: 6 | 7 | - [Static and Dynamic Rendering](https://nextjs.org/learn/dashboard-app/static-and-dynamic-rendering) -------------------------------------------------------------------------------- /day-94/README.md: -------------------------------------------------------------------------------- 1 | # Day-94 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-94 Task:** 4 | 5 | Today's task is to learn about: 6 | 7 | - [Adding Search and Pagination](https://nextjs.org/learn/dashboard-app/adding-search-and-pagination) -------------------------------------------------------------------------------- /day-12/q35/main.ts: -------------------------------------------------------------------------------- 1 | let animals: string[] = ["dog", "cat", "rabbit"]; 2 | 3 | animals.forEach((animal) => { 4 | console.log(`A ${animal} would make a great pet.`); 5 | }); 6 | console.log("Any of these animals would make a great pet!"); 7 | -------------------------------------------------------------------------------- /day-13/q38/main.ts: -------------------------------------------------------------------------------- 1 | function describe_city(city: string, country: string = "Pakistan") { 2 | console.log(`${city} is in ${country}.`); 3 | } 4 | 5 | describe_city("Karachi"); 6 | describe_city("Lahore"); 7 | describe_city("Tokyo", "Japan"); -------------------------------------------------------------------------------- /day-14/q41/main.js: -------------------------------------------------------------------------------- 1 | var magicians = ["Alice", "David", "Chris"]; 2 | function show_magicians(magicians) { 3 | magicians.forEach(function (magician) { 4 | console.log(magician); 5 | }); 6 | } 7 | show_magicians(magicians); 8 | -------------------------------------------------------------------------------- /day-40/q118/main.ts: -------------------------------------------------------------------------------- 1 | // This loop logs numbers from 1 to 10 2 | for (let i = 1; i <= 10; i++) { 3 | console.log(i); // Logs the current value of i 4 | } 5 | // Each iteration increases the value of i by 1, logging it until it reaches 10. 6 | -------------------------------------------------------------------------------- /day-74/README.md: -------------------------------------------------------------------------------- 1 | # Day-74 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-74 Task:** 4 | 5 | Learn about TypeScript Debugging by using the following guide and debug along with it: 6 | 7 | [Debugging in TypeScript](./TS-debugging/README.md) -------------------------------------------------------------------------------- /day-78/README.md: -------------------------------------------------------------------------------- 1 | # Day-78 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-78 Task:** 4 | 5 | Read and understand the following Visual Guide about the Web Vitals. 6 | 7 | [What are Web Vitals?](https://roadmap.sh/guides/what-are-web-vitals) -------------------------------------------------------------------------------- /day-12/q35/main.js: -------------------------------------------------------------------------------- 1 | var animals = ["dog", "cat", "rabbit"]; 2 | animals.forEach(function (animal) { 3 | console.log("A ".concat(animal, " would make a great pet.")); 4 | }); 5 | console.log("Any of these animals would make a great pet!"); 6 | -------------------------------------------------------------------------------- /day-40/q118/main.js: -------------------------------------------------------------------------------- 1 | // This loop logs numbers from 1 to 10 2 | for (var i = 1; i <= 10; i++) { 3 | console.log(i); // Logs the current value of i 4 | } 5 | // Each iteration increases the value of i by 1, logging it until it reaches 10. 6 | -------------------------------------------------------------------------------- /day-65/TS-Function/04-Arrow-Function.ts: -------------------------------------------------------------------------------- 1 | /****************** 2 | * ARROW FUNCTION * 3 | ******************/ 4 | 5 | const addWithArrow = (num1: number, num2: number): number => num1 + num2; 6 | console.log(addWithArrow(10, 20)); // Output: 30 7 | -------------------------------------------------------------------------------- /day-08/q22/main.js: -------------------------------------------------------------------------------- 1 | var friends = ["Alice", "Bob", "Charlie"]; 2 | console.log(friends[3]); // Intentional error: Arrays are zero-indexed, so index 3 is out of bounds. 3 | friends[2] = "Charlie"; // Correcting the error by accessing a valid index. 4 | -------------------------------------------------------------------------------- /day-69/README.md: -------------------------------------------------------------------------------- 1 | # Day-69 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-69 Task:** 4 | 5 | Learn about TypeScript enums by using the following guide and coding along with the examples provided in it: 6 | 7 | [Enums in TypeScript](./TS-Enums/README.md) -------------------------------------------------------------------------------- /day-07/q21/main.js: -------------------------------------------------------------------------------- 1 | var book = { 2 | title: "The Hobbit", 3 | author: "J.R.R. Tolkien", 4 | yearPublished: 1937 5 | }; 6 | console.log("Book Info: ".concat(book.title, " by ").concat(book.author, ", published in ").concat(book.yearPublished)); 7 | -------------------------------------------------------------------------------- /day-34/q102/main.js: -------------------------------------------------------------------------------- 1 | // Calculates the absolute difference between -5 and 5 2 | var difference = Math.abs(-5 - 5); 3 | console.log(difference); // Outputs: 10 4 | // This line shows the absolute value of the difference between -5 and 5, ignoring the sign. 5 | -------------------------------------------------------------------------------- /day-44/q130/main.ts: -------------------------------------------------------------------------------- 1 | // In another file where you want to use the add function: 2 | import { add } from "./mathFunction"; 3 | 4 | console.log(add(2, 3)); // Outputs: 5 5 | // Demonstrates importing the add function from mathFunctions.ts and using it. 6 | -------------------------------------------------------------------------------- /day-73/TS-Type-Assertions/01-Type-Assertions.ts: -------------------------------------------------------------------------------- 1 | /******************* 2 | * TYPE ASSERTIONS * 3 | *******************/ 4 | 5 | let data: any = "1000"; 6 | 7 | // Type assertion to treat "data" as a string 8 | console.log((data as string).repeat(3)); 9 | -------------------------------------------------------------------------------- /day-77/README.md: -------------------------------------------------------------------------------- 1 | # Day-77 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-77 Task:** 4 | 5 | Read and understand the following Visual Guide about SSL, TLS, and SSH protocols. 6 | 7 | [SSL vs TLS vs SSH Protocols](https://roadmap.sh/guides/ssl-tls-https-ssh) -------------------------------------------------------------------------------- /day-08/q22/main.ts: -------------------------------------------------------------------------------- 1 | let friends: string[] = ["Alice", "Bob", "Charlie"]; 2 | console.log(friends[3]); // Intentional error: Arrays are zero-indexed, so index 3 is out of bounds. 3 | friends[2] = "Charlie"; // Correcting the error by accessing a valid index. 4 | -------------------------------------------------------------------------------- /day-44/q131/main.ts: -------------------------------------------------------------------------------- 1 | // In another file: 2 | import { Person } from "./Person"; 3 | 4 | const alice = new Person("Alice"); 5 | alice.greet(); // Outputs: Hello, my name is Alice 6 | // This snippet imports the Person class and uses it to create an instance. 7 | -------------------------------------------------------------------------------- /day-50/q148/main.ts: -------------------------------------------------------------------------------- 1 | // Uses setTimeout to log a message after a 2-second delay 2 | setTimeout(() => { 3 | console.log("This message is shown after a 2-second delay."); 4 | }, 2000); 5 | // This showcases how to use setTimeout to delay actions in your code. 6 | -------------------------------------------------------------------------------- /day-54/README.md: -------------------------------------------------------------------------------- 1 | # Day-54 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-54 Task:** 4 | 5 | Read the following Articles and Code along with it: 6 | 7 | [Hello World](https://javascript.info/hello-world) 8 | 9 | [Variables](https://javascript.info/variables) -------------------------------------------------------------------------------- /day-63/README.md: -------------------------------------------------------------------------------- 1 | # Day-63 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-63 Task:** 4 | 5 | Learn about TypeScript types by using the following guide and coding along with the examples provided in it: 6 | 7 | [Multiple Types in TypeScript](./TS-Types/README.md) -------------------------------------------------------------------------------- /day-72/README.md: -------------------------------------------------------------------------------- 1 | # Day-72 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-72 Task:** 4 | 5 | Learn about TypeScript generics by using the following guide and coding along with the examples provided in it: 6 | 7 | [Generics in TypeScript](./TS-Generics/README.md) -------------------------------------------------------------------------------- /day-04/q12/main.js: -------------------------------------------------------------------------------- 1 | var names = ["Alice", "Bob", "Charlie"]; 2 | for (var _i = 0, names_1 = names; _i < names_1.length; _i++) { 3 | var name_1 = names_1[_i]; 4 | console.log("Hello ".concat(name_1, ", would you like to learn some TypeScript today?")); 5 | } 6 | -------------------------------------------------------------------------------- /day-14/q41/main.ts: -------------------------------------------------------------------------------- 1 | let magicians: string[] = ["Alice", "David", "Chris"]; 2 | 3 | function show_magicians(magicians: string[]) { 4 | magicians.forEach((magician) => { 5 | console.log(magician); 6 | }); 7 | } 8 | 9 | show_magicians(magicians); 10 | -------------------------------------------------------------------------------- /day-68/README.md: -------------------------------------------------------------------------------- 1 | # Day-68 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-68 Task:** 4 | 5 | Learn about TypeScript tuples by using the following guide and coding along with the examples provided in it: 6 | 7 | [Tuple Data Type in TypeScript](./TS-Tuple/README.md) -------------------------------------------------------------------------------- /day-70/README.md: -------------------------------------------------------------------------------- 1 | # Day-70 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-70 Task:** 4 | 5 | Learn about TypeScript interfaces by using the following guide and coding along with the examples provided in it: 6 | 7 | [Interface in TypeScript](./TS-Interface/README.md) -------------------------------------------------------------------------------- /day-13/q39/main.js: -------------------------------------------------------------------------------- 1 | function city_country(city, country) { 2 | return "".concat(city, ", ").concat(country); 3 | } 4 | console.log(city_country("Lahore", "Pakistan")); 5 | console.log(city_country("Tokyo", "Japan")); 6 | console.log(city_country("Paris", "France")); 7 | -------------------------------------------------------------------------------- /day-16/q46/main.ts: -------------------------------------------------------------------------------- 1 | let laptop = { 2 | make: "Dell", 3 | model: "New Elite Series", 4 | year: 2024, 5 | describe: function () { 6 | console.log(`This laptop is a ${this.year} ${this.make} ${this.model}.`); 7 | }, 8 | }; 9 | laptop.describe(); 10 | -------------------------------------------------------------------------------- /day-34/q102/main.ts: -------------------------------------------------------------------------------- 1 | // Calculates the absolute difference between -5 and 5 2 | const difference: number = Math.abs(-5 - 5); 3 | 4 | console.log(difference); // Outputs: 10 5 | // This line shows the absolute value of the difference between -5 and 5, ignoring the sign. 6 | -------------------------------------------------------------------------------- /day-50/q148/main.js: -------------------------------------------------------------------------------- 1 | // Uses setTimeout to log a message after a 2-second delay 2 | setTimeout(function () { 3 | console.log("This message is shown after a 2-second delay."); 4 | }, 2000); 5 | // This showcases how to use setTimeout to delay actions in your code. 6 | -------------------------------------------------------------------------------- /day-65/README.md: -------------------------------------------------------------------------------- 1 | # Day-65 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-65 Task:** 4 | 5 | Learn about TypeScript functions by using the following guide and coding along with the examples provided in it: 6 | 7 | [Type Annotations With Function](./TS-Function/README.md) -------------------------------------------------------------------------------- /day-66/TS-Type-System-Concepts/02-Literal-Types.ts: -------------------------------------------------------------------------------- 1 | /***************** 2 | * LITERAL TYPES * 3 | *****************/ 4 | 5 | let direction: "left" | "right" | "up" | "down"; 6 | 7 | function setColor(color: "red" | "green" | "blue") { 8 | // ... 9 | } 10 | -------------------------------------------------------------------------------- /day-71/README.md: -------------------------------------------------------------------------------- 1 | # Day-71 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-71 Task:** 4 | 5 | Learn about TypeScript classes by using the following guide and coding along with the examples provided in it: 6 | 7 | [Class Type Annotations in TypeScript](./TS-Class/README.md) -------------------------------------------------------------------------------- /day-86/README.md: -------------------------------------------------------------------------------- 1 | # Day-86 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-86 Task:** 4 | 5 | Today's task is to learn about: 6 | 7 | - [Learn Next.js](https://nextjs.org/learn/dashboard-app) 8 | - [Getting Started](https://nextjs.org/learn/dashboard-app/getting-started) -------------------------------------------------------------------------------- /day-65/TS-Function/05-Anonymous-Function.ts: -------------------------------------------------------------------------------- 1 | /********************** 2 | * ANONYMOUS FUNCTION * 3 | **********************/ 4 | 5 | const add = function (num1: number, num2: number): number { 6 | return num1 + num2; 7 | }; 8 | console.log(add(10, 20)); // Output: 30 9 | -------------------------------------------------------------------------------- /day-67/README.md: -------------------------------------------------------------------------------- 1 | # Day-67 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-67 Task:** 4 | 5 | Learn about TypeScript arrays by using the following guide and coding along with the examples provided in it: 6 | 7 | [Type Annotations With Arrays in TypeScript](./TS-Array/README.md) -------------------------------------------------------------------------------- /day-64/README.md: -------------------------------------------------------------------------------- 1 | # Day-64 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-64 Task:** 4 | 5 | Learn about TypeScript objects by using the following guide and coding along with the examples provided in it: 6 | 7 | [Type Annotations with Objects in TypeScript](./TS-Object/README.md) -------------------------------------------------------------------------------- /day-73/README.md: -------------------------------------------------------------------------------- 1 | # Day-73 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-73 Task:** 4 | 5 | Learn about TypeScript type assertions by using the following guide and coding along with the examples provided in it: 6 | 7 | [Type Assertions in TypeScript](./TS-Type-Assertions/README.md) -------------------------------------------------------------------------------- /day-07/q21/main.ts: -------------------------------------------------------------------------------- 1 | let book: { title: string; author: string; yearPublished: number } = { 2 | title: "The Hobbit", 3 | author: "J.R.R. Tolkien", 4 | yearPublished: 1937 5 | }; 6 | console.log(`Book Info: ${book.title} by ${book.author}, published in ${book.yearPublished}`); -------------------------------------------------------------------------------- /day-13/q39/main.ts: -------------------------------------------------------------------------------- 1 | function city_country(city: string, country: string): string { 2 | return `${city}, ${country}`; 3 | } 4 | 5 | console.log(city_country("Lahore", "Pakistan")); 6 | console.log(city_country("Tokyo", "Japan")); 7 | console.log(city_country("Paris", "France")); 8 | -------------------------------------------------------------------------------- /day-44/q132/main.ts: -------------------------------------------------------------------------------- 1 | // Importing named exports: 2 | import { utilOne, utilTwo } from "./utils"; 3 | 4 | // Importing a default export: 5 | import Calculator from "./Calculator"; 6 | 7 | // This code illustrates the syntax and usage differences between default and named exports. 8 | -------------------------------------------------------------------------------- /day-70/TS-Interface/01-Interface-Intro.ts: -------------------------------------------------------------------------------- 1 | /******************* 2 | * INTERFACE INTRO * 3 | *******************/ 4 | 5 | interface PersonEx1 { 6 | name: string; 7 | age: number; 8 | } 9 | 10 | const John: PersonEx1 = { 11 | name: "John", 12 | age: 30, 13 | }; 14 | -------------------------------------------------------------------------------- /day-74/TS-debugging/01-debugging.ts: -------------------------------------------------------------------------------- 1 | /************* 2 | * DEBUGGING * 3 | *************/ 4 | 5 | let age: number = 22; 6 | if (age > 20) { 7 | console.log("pass"); 8 | } else if (age < 20) { 9 | console.log("return"); 10 | } else { 11 | console.log("reboot"); 12 | } 13 | -------------------------------------------------------------------------------- /day-13/q38/main.js: -------------------------------------------------------------------------------- 1 | function describe_city(city, country) { 2 | if (country === void 0) { country = "Pakistan"; } 3 | console.log("".concat(city, " is in ").concat(country, ".")); 4 | } 5 | describe_city("Karachi"); 6 | describe_city("Lahore"); 7 | describe_city("Tokyo", "Japan"); 8 | -------------------------------------------------------------------------------- /day-15/q44/main.ts: -------------------------------------------------------------------------------- 1 | function make_sandwich(...items: string[]) { 2 | console.log(`Making a sandwich with: ${items.join(", ")}.`); 3 | } 4 | 5 | make_sandwich("ham", "cheese"); 6 | make_sandwich("turkey", "lettuce", "tomato"); 7 | make_sandwich("avocado", "sprouts", "mustard", "mayo"); 8 | -------------------------------------------------------------------------------- /day-44/q131/Person.ts: -------------------------------------------------------------------------------- 1 | // In file: Person.ts 2 | export class Person { 3 | name: string; 4 | constructor(name: string) { 5 | this.name = name; 6 | } 7 | greet() { 8 | console.log(`Hello, my name is ${this.name}`); 9 | } 10 | } 11 | // Exports the Person class 12 | -------------------------------------------------------------------------------- /day-11/q31/main.ts: -------------------------------------------------------------------------------- 1 | let usernames: string[] = []; 2 | 3 | if(usernames.length === 0){ 4 | console.log("We need to find some users!"); 5 | 6 | } else { 7 | // Greet Users 8 | } 9 | 10 | // Removing all usernames ensures the message "We need to find some users!" is printed. -------------------------------------------------------------------------------- /day-56/README.md: -------------------------------------------------------------------------------- 1 | # Day-56 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-56 Task:** 4 | 5 | Read the following Articles and Code along with it: 6 | 7 | [Type Conversions in JavaScript](https://javascript.info/type-conversions) 8 | 9 | [Operators in JavaScript](https://javascript.info/operators) -------------------------------------------------------------------------------- /day-75/README.md: -------------------------------------------------------------------------------- 1 | # Day-75 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-75 Task:** 4 | 5 | Read the following Article with interactive videos about How does the internet work? behind the scenes what happens, etc. 6 | 7 | [How does the internet work?](https://roadmap.sh/guides/what-is-internet) -------------------------------------------------------------------------------- /day-50/q149/main.js: -------------------------------------------------------------------------------- 1 | console.log("Start"); 2 | setTimeout(function () { 3 | console.log("Callback executed"); // This gets queued to be executed by the event loop 4 | }, 0); 5 | console.log("End"); 6 | // Although the timeout is 0, "Callback executed" is logged after "End" due to the event loop. 7 | -------------------------------------------------------------------------------- /day-76/README.md: -------------------------------------------------------------------------------- 1 | # Day-76 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-76 Task:** 4 | 5 | Read and understand the following Visual Guide about DNS and DHCP. 6 | 7 | [What is DNS?](https://roadmap.sh/guides/dns-in-one-picture) 8 | 9 | [What is DHCP?](https://roadmap.sh/guides/dhcp-in-one-picture) -------------------------------------------------------------------------------- /day-87/README.md: -------------------------------------------------------------------------------- 1 | # Day-87 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-87 Task:** 4 | 5 | Today's task is to learn about: 6 | 7 | - [CSS Styling](https://nextjs.org/learn/dashboard-app/css-styling) 8 | - [Optimizing Fonts and Images](https://nextjs.org/learn/dashboard-app/optimizing-fonts-images) -------------------------------------------------------------------------------- /day-16/q47/main.ts: -------------------------------------------------------------------------------- 1 | let laptops = [ 2 | { make: "Dell", model: "XPS 15", year: 2021 }, 3 | { make: "Apple", model: "MacBook Pro", year: 2020 }, 4 | { make: "HP", model: "Spectre x360", year: 2021 }, 5 | ]; 6 | let [laptop1, laptop2] = laptops; 7 | console.log(laptop1); 8 | console.log(laptop2); 9 | -------------------------------------------------------------------------------- /day-44/q130/mathFunction.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.add = void 0; 4 | // In file: mathFunctions.ts 5 | var add = function (a, b) { return a + b; }; 6 | exports.add = add; 7 | // This line exports an add function from mathFunctions.ts 8 | -------------------------------------------------------------------------------- /day-50/q149/main.ts: -------------------------------------------------------------------------------- 1 | console.log("Start"); 2 | 3 | setTimeout(() => { 4 | console.log("Callback executed"); // This gets queued to be executed by the event loop 5 | }, 0); 6 | 7 | console.log("End"); 8 | // Although the timeout is 0, "Callback executed" is logged after "End" due to the event loop. 9 | -------------------------------------------------------------------------------- /day-59/README.md: -------------------------------------------------------------------------------- 1 | # Day-59 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-59 Task:** 4 | 5 | Read the following Articles and Code along with it: 6 | 7 | [Loops: while and for in JavaScript](https://javascript.info/while-for) 8 | 9 | [The "switch" statement in JavaScript](https://javascript.info/switch) -------------------------------------------------------------------------------- /day-66/README.md: -------------------------------------------------------------------------------- 1 | # Day-66 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-66 Task:** 4 | 5 | Learn about different TypeScript type system concepts by using the following guide and coding along with the examples provided in it: 6 | 7 | [TypeScript Type System Concepts](./TS-Type-System-Concepts/README.md) -------------------------------------------------------------------------------- /day-16/q46/main.js: -------------------------------------------------------------------------------- 1 | var laptop = { 2 | make: "Dell", 3 | model: "New Elite Series", 4 | year: 2024, 5 | describe: function () { 6 | console.log("This laptop is a ".concat(this.year, " ").concat(this.make, " ").concat(this.model, ".")); 7 | }, 8 | }; 9 | laptop.describe(); 10 | -------------------------------------------------------------------------------- /day-60/README.md: -------------------------------------------------------------------------------- 1 | # Day-60 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-60 Task:** 4 | 5 | Read the following Articles and Code along with it: 6 | 7 | [Functions in JavaScript](https://javascript.info/function-basics) 8 | 9 | [Function Expressions in JavaScript](https://javascript.info/function-expressions) -------------------------------------------------------------------------------- /day-10/q29/main.js: -------------------------------------------------------------------------------- 1 | var favorite_fruits = ["apples", "bananas", "cherries"]; 2 | if (favorite_fruits.includes("bananas")) { 3 | console.log("You really like bananas!"); 4 | } 5 | if (favorite_fruits.includes("apples")) { 6 | console.log("You really like apples!"); 7 | } 8 | // Continue with more fruits 9 | -------------------------------------------------------------------------------- /day-34/README.md: -------------------------------------------------------------------------------- 1 | # Day-34 of `100-Days-Of-Code` Challenge 2 | 3 | **Question 100:** Use the JavaScript Math object to find the square root of 144. 4 | 5 | **Question 101:** Generate a random integer between 1 and 10. 6 | 7 | **Question 102:** Calculate and log the absolute difference between the number -5 and 5. -------------------------------------------------------------------------------- /day-55/README.md: -------------------------------------------------------------------------------- 1 | # Day-55 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-55 Task:** 4 | 5 | Read the following Articles and Code along with it: 6 | 7 | [Data Types in JavaScript](https://javascript.info/types) 8 | 9 | [Interaction: alert, prompt, confirm in JavaScript](https://javascript.info/alert-prompt-confirm) -------------------------------------------------------------------------------- /day-69/TS-Enums/01-Enums.ts: -------------------------------------------------------------------------------- 1 | /********* 2 | * ENUMS * 3 | *********/ 4 | 5 | enum Days { 6 | Sunday, 7 | Monday, 8 | Tuesday, 9 | Wednesday, 10 | Thursday, 11 | Friday, 12 | Saturday, 13 | } 14 | 15 | const today: Days = Days.Wednesday; 16 | 17 | console.log(`Today is ${Days[today]}`); 18 | -------------------------------------------------------------------------------- /day-80/README.md: -------------------------------------------------------------------------------- 1 | # Day-80 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-80 Task:** 4 | 5 | Read the following Article about the difference between Full Stack Developer or Software Engineer. 6 | 7 | [Full Stack Developer or Software Engineer – Which Way to Go?](https://roadmap.sh/full-stack/vs-software-engineer) -------------------------------------------------------------------------------- /day-40/q119/main.js: -------------------------------------------------------------------------------- 1 | // Initializes a counter 2 | var count = 0; 3 | // This while loop runs until count is 5 4 | while (count < 5) { 5 | console.log("Hello, World!"); // Logs "Hello, World!" 6 | count++; // Increments count by 1 7 | } 8 | // Repeats logging "Hello, World!" 5 times, once per loop iteration. 9 | -------------------------------------------------------------------------------- /day-40/q119/main.ts: -------------------------------------------------------------------------------- 1 | // Initializes a counter 2 | let count: number = 0; 3 | // This while loop runs until count is 5 4 | while (count < 5) { 5 | console.log("Hello, World!"); // Logs "Hello, World!" 6 | count++; // Increments count by 1 7 | } 8 | // Repeats logging "Hello, World!" 5 times, once per loop iteration. 9 | -------------------------------------------------------------------------------- /day-57/README.md: -------------------------------------------------------------------------------- 1 | # Day-57 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-57 Task:** 4 | 5 | Read the following Articles and Code along with it: 6 | 7 | [Comparisons in JavaScript](https://javascript.info/comparison) 8 | 9 | [Conditional Operators: if, '?'(Ternary Operator) in JavaScript](https://javascript.info/ifelse) -------------------------------------------------------------------------------- /day-85/README.md: -------------------------------------------------------------------------------- 1 | # Day-85 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-85 Task:** 4 | 5 | Today's task is to learn about: 6 | 7 | - [Installing Next.js](https://nextjs.org/learn/react-foundations/installation) 8 | - [Server and Client Components](https://nextjs.org/learn/react-foundations/server-and-client-components) -------------------------------------------------------------------------------- /day-16/q47/main.js: -------------------------------------------------------------------------------- 1 | var laptops = [ 2 | { make: "Dell", model: "XPS 15", year: 2021 }, 3 | { make: "Apple", model: "MacBook Pro", year: 2020 }, 4 | { make: "HP", model: "Spectre x360", year: 2021 }, 5 | ]; 6 | var laptop1 = laptops[0], laptop2 = laptops[1]; 7 | console.log(laptop1); 8 | console.log(laptop2); 9 | -------------------------------------------------------------------------------- /day-41/q121/main.ts: -------------------------------------------------------------------------------- 1 | // This for loop counts from 1 to 10 but skips 5 2 | for (let i = 1; i <= 10; i++) { 3 | if (i === 5) { 4 | continue; // Skips the rest of the loop for i = 5 5 | } 6 | console.log(i); // Logs numbers 1-4 and 6-10 7 | } 8 | // It demonstrates how to use 'continue' to skip a specific iteration. 9 | -------------------------------------------------------------------------------- /day-47/q140/main.js: -------------------------------------------------------------------------------- 1 | // Attempting to use a reserved word as a variable name 2 | // let if = 5; // This line would cause a syntax error 3 | console.log("Using a reserved word as a variable name causes a syntax error in JavaScript."); 4 | // It's important to avoid using reserved words as identifiers to prevent these errors. 5 | -------------------------------------------------------------------------------- /day-88/README.md: -------------------------------------------------------------------------------- 1 | # Day-88 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-88 Task:** 4 | 5 | Today's task is to learn about: 6 | 7 | - [Creating Layouts and Pages](https://nextjs.org/learn/dashboard-app/creating-layouts-and-pages) 8 | - [Navigating Between Pages](https://nextjs.org/learn/dashboard-app/navigating-between-pages) -------------------------------------------------------------------------------- /day-08/q23/main.js: -------------------------------------------------------------------------------- 1 | var car = "subaru"; 2 | console.log("Is car == 'subaru'? I predict true"); 3 | console.log(car == "subaru"); 4 | console.log("Is car == 'toyota'? I predict false"); 5 | console.log(car == "toyota"); 6 | // Create at least 10 tests. Have at least 5 tests evaluate to True and another 5 tests evaluate to False. 7 | -------------------------------------------------------------------------------- /day-37/q109/main.js: -------------------------------------------------------------------------------- 1 | // Checks the current hour and logs "Good Morning" if it's before 12 PM 2 | var currentTime = new Date(); 3 | if (currentTime.getHours() < 12) { 4 | console.log("Good Morning"); // It's morning if before 12 PM 5 | } 6 | // This simple check helps us greet users appropriately based on the time of day. 7 | -------------------------------------------------------------------------------- /day-37/q109/main.ts: -------------------------------------------------------------------------------- 1 | // Checks the current hour and logs "Good Morning" if it's before 12 PM 2 | const currentTime = new Date(); 3 | if (currentTime.getHours() < 12) { 4 | console.log("Good Morning"); // It's morning if before 12 PM 5 | } 6 | // This simple check helps us greet users appropriately based on the time of day. 7 | -------------------------------------------------------------------------------- /day-61/README.md: -------------------------------------------------------------------------------- 1 | # Day-61 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-61 Task:** 4 | 5 | Read the following Articles and Code along with it: 6 | 7 | [Arrow functions Basics in JavaScript](https://javascript.info/arrow-functions-basics) 8 | 9 | [JavaScript specials in JavaScript](https://javascript.info/javascript-specials) -------------------------------------------------------------------------------- /day-09/q25/main.js: -------------------------------------------------------------------------------- 1 | // Version that passes: 2 | var alien_color = "green"; 3 | if (alien_color == "green") { 4 | console.log("You just earned 5 points!"); 5 | } 6 | // Version that fails (no output): 7 | alien_color = "red"; 8 | if (alien_color == "green") { 9 | // No output because the condition is false 10 | } 11 | -------------------------------------------------------------------------------- /day-09/q25/main.ts: -------------------------------------------------------------------------------- 1 | // Version that passes: 2 | let alien_color = "green"; 3 | if (alien_color == "green") { 4 | console.log("You just earned 5 points!"); 5 | } 6 | 7 | // Version that fails (no output): 8 | alien_color = "red"; 9 | if (alien_color == "green") { 10 | // No output because the condition is false 11 | } 12 | -------------------------------------------------------------------------------- /day-10/q29/main.ts: -------------------------------------------------------------------------------- 1 | let favorite_fruits: string[] = ["apples", "bananas", "cherries"]; 2 | 3 | if (favorite_fruits.includes("bananas")) { 4 | console.log("You really like bananas!"); 5 | } 6 | if (favorite_fruits.includes("apples")) { 7 | console.log("You really like apples!"); 8 | } 9 | // Continue with more fruits 10 | -------------------------------------------------------------------------------- /day-41/q121/main.js: -------------------------------------------------------------------------------- 1 | // This for loop counts from 1 to 10 but skips 5 2 | for (var i = 1; i <= 10; i++) { 3 | if (i === 5) { 4 | continue; // Skips the rest of the loop for i = 5 5 | } 6 | console.log(i); // Logs numbers 1-4 and 6-10 7 | } 8 | // It demonstrates how to use 'continue' to skip a specific iteration. 9 | -------------------------------------------------------------------------------- /day-45/README.md: -------------------------------------------------------------------------------- 1 | # Day-45 of `100-Days-Of-Code` Challenge 2 | 3 | **Question 133:** Write a JavaScript object and convert it into a JSON string. 4 | 5 | **Question 134:** Take a JSON string and parse it into a JavaScript object. 6 | 7 | **Question 135:** Explain how you can format a JSON string with proper indentation for readability. -------------------------------------------------------------------------------- /day-84/README.md: -------------------------------------------------------------------------------- 1 | # Day-84 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-84 Task:** 4 | 5 | Today's task is to learn about: 6 | 7 | - [Adding Interactivity with State](https://nextjs.org/learn/react-foundations/updating-state) 8 | - [Displaying Data with Props](https://nextjs.org/learn/react-foundations/displaying-data-with-props) 9 | -------------------------------------------------------------------------------- /day-08/q23/main.ts: -------------------------------------------------------------------------------- 1 | let car = "subaru"; 2 | 3 | console.log("Is car == 'subaru'? I predict true"); 4 | console.log(car == "subaru"); 5 | 6 | console.log("Is car == 'toyota'? I predict false"); 7 | console.log(car == "toyota"); 8 | 9 | // Create at least 10 tests. Have at least 5 tests evaluate to True and another 5 tests evaluate to False. -------------------------------------------------------------------------------- /day-31/q91/main.js: -------------------------------------------------------------------------------- 1 | // Defines an array with three favorite fruits 2 | var favoriteFruits = ["Apple", "Banana", "Cherry"]; 3 | favoriteFruits.push("Mango"); // Adds "Mango" to the end of the array 4 | console.log(favoriteFruits); // Outputs: ['Apple', 'Banana', 'Cherry', 'Mango'] 5 | // This line adds a new fruit to our list of favorites. 6 | -------------------------------------------------------------------------------- /day-34/q101/main.js: -------------------------------------------------------------------------------- 1 | // Generates a random integer between 1 and 10 2 | function getRandomInt() { 3 | return Math.floor(Math.random() * 10) + 1; 4 | } 5 | console.log(getRandomInt()); // Outputs a random integer between 1 and 10 6 | // This function combines Math.random() with Math.floor() to create a random integer within our range. 7 | -------------------------------------------------------------------------------- /day-40/README.md: -------------------------------------------------------------------------------- 1 | # Day-40 of `100-Days-Of-Code` Challenge 2 | 3 | **Question 118:** Write a loop that logs numbers from 1 to 10 to the console. 4 | 5 | **Question 119:** Create a while loop that logs "Hello, World!" 5 times. 6 | 7 | **Question 120:** Use a for...of loop to iterate through an array of your favorite movies and log each one. -------------------------------------------------------------------------------- /day-49/README.md: -------------------------------------------------------------------------------- 1 | # Day-49 of `100-Days-Of-Code` Challenge 2 | 3 | **Question 145:** Create a function that accepts a callback and invokes it with some arguments. 4 | 5 | **Question 146:** Show an example of a callback function used to filter an array of numbers. 6 | 7 | **Question 147:** Explain how to handle errors in a callback pattern. -------------------------------------------------------------------------------- /day-58/README.md: -------------------------------------------------------------------------------- 1 | # Day-58 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-58 Task:** 4 | 5 | Read the following Articles and Code along with it: 6 | 7 | [Logical Operators in JavaScript](https://javascript.info/logical-operators) 8 | 9 | [Nullish Coalescing Operator '??' in JavaScript](https://javascript.info/nullish-coalescing-operator) -------------------------------------------------------------------------------- /day-82/README.md: -------------------------------------------------------------------------------- 1 | # Day-82 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-82 Task:** 4 | 5 | Today's task is to learn about: 6 | 7 | - [Updating UI with Javascript](https://nextjs.org/learn/react-foundations/updating-ui-with-javascript) 8 | - [Getting Started with React](https://nextjs.org/learn/react-foundations/getting-started-with-react) -------------------------------------------------------------------------------- /day-83/README.md: -------------------------------------------------------------------------------- 1 | # Day-83 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-83 Task:** 4 | 5 | Today's task is to learn about: 6 | 7 | - [Building UI with Components](https://nextjs.org/learn/react-foundations/building-ui-with-components) 8 | - [Displaying Data with Props](https://nextjs.org/learn/react-foundations/displaying-data-with-props) -------------------------------------------------------------------------------- /day-01/q3/main.js: -------------------------------------------------------------------------------- 1 | var myName = "Asharib"; // This saves the name 2 | console.log(myName.toLowerCase()); // Shows the name in all small letters 3 | console.log(myName.toUpperCase()); // Shows the name in ALL BIG LETTERS 4 | console.log(myName.charAt(0).toUpperCase() + myName.slice(1).toLowerCase()); // Shows the name with the First Letter Big 5 | -------------------------------------------------------------------------------- /day-22/q65/main.js: -------------------------------------------------------------------------------- 1 | // This function finds the leftover of dividing two numbers 2 | function remainder(num1, num2) { 3 | // Gives back the leftover of num1 divided by num2 4 | return num1 % num2; 5 | } 6 | // Trying it with 5 divided by 2 7 | console.log(remainder(5, 2)); // Shows 1 8 | // This tells us the leftover, which is 1 here. 9 | -------------------------------------------------------------------------------- /day-47/q140/main.ts: -------------------------------------------------------------------------------- 1 | // Attempting to use a reserved word as a variable name 2 | // let if = 5; // This line would cause a syntax error 3 | 4 | console.log( 5 | "Using a reserved word as a variable name causes a syntax error in JavaScript." 6 | ); 7 | // It's important to avoid using reserved words as identifiers to prevent these errors. 8 | -------------------------------------------------------------------------------- /day-17/q50/main.js: -------------------------------------------------------------------------------- 1 | // Using template literals to define a multiline string 2 | var myIdealDay = "My ideal day would involve:\n1. Waking up early and going for a jog.\n2. Spending a few hours coding on a personal project.\n3. Ending the day by reading a good book."; 3 | // Logging the multiline string to the console 4 | console.log(myIdealDay); 5 | -------------------------------------------------------------------------------- /day-34/q101/main.ts: -------------------------------------------------------------------------------- 1 | // Generates a random integer between 1 and 10 2 | function getRandomInt(): number { 3 | return Math.floor(Math.random() * 10) + 1; 4 | } 5 | 6 | console.log(getRandomInt()); // Outputs a random integer between 1 and 10 7 | // This function combines Math.random() with Math.floor() to create a random integer within our range. 8 | -------------------------------------------------------------------------------- /day-44/q131/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | // In another file: 4 | var Person_1 = require("./Person"); 5 | var alice = new Person_1.Person("Alice"); 6 | alice.greet(); // Outputs: Hello, my name is Alice 7 | // This snippet imports the Person class and uses it to create an instance. 8 | -------------------------------------------------------------------------------- /day-01/q3/main.ts: -------------------------------------------------------------------------------- 1 | let myName: string = "Asharib"; // This saves the name 2 | 3 | console.log(myName.toLowerCase()); // Shows the name in all small letters 4 | console.log(myName.toUpperCase()); // Shows the name in ALL BIG LETTERS 5 | console.log(myName.charAt(0).toUpperCase() + myName.slice(1).toLowerCase()); // Shows the name with the First Letter Big -------------------------------------------------------------------------------- /day-18/q52/main.ts: -------------------------------------------------------------------------------- 1 | // Sets up details about a smartphone 2 | let smartphone = { 3 | make: "Samsung", 4 | model: "Galaxy S21", 5 | specs: { 6 | storage: "128GB", 7 | screenSize: "6.2 inches", 8 | batteryLife: "18 hours", 9 | }, 10 | }; 11 | 12 | // Shows what we've set up about the smartphone 13 | console.log(smartphone); 14 | -------------------------------------------------------------------------------- /day-31/q91/main.ts: -------------------------------------------------------------------------------- 1 | // Defines an array with three favorite fruits 2 | let favoriteFruits: string[] = ["Apple", "Banana", "Cherry"]; 3 | favoriteFruits.push("Mango"); // Adds "Mango" to the end of the array 4 | 5 | console.log(favoriteFruits); // Outputs: ['Apple', 'Banana', 'Cherry', 'Mango'] 6 | // This line adds a new fruit to our list of favorites. 7 | -------------------------------------------------------------------------------- /day-35/README.md: -------------------------------------------------------------------------------- 1 | # Day-35 of `100-Days-Of-Code` Challenge 2 | 3 | **Question 103:** Write a function that returns a random boolean value, true or false. 4 | 5 | **Question 104:** Create a function that generates a random hexadecimal color code. 6 | 7 | **Question 105:** Simulate a dice roll using JavaScript and return a random integer between 1 and 6. -------------------------------------------------------------------------------- /day-46/q136/main.ts: -------------------------------------------------------------------------------- 1 | // Demonstrates using console.log() inside a loop to track variable values 2 | for (let i = 1; i <= 5; i++) { 3 | console.log(`Iteration ${i}, i value:, i`); // Logs the current iteration number and the value of i 4 | } 5 | // This loop iterates five times, logging the value of 'i' during each iteration to help with debugging. 6 | -------------------------------------------------------------------------------- /day-10/q30/main.ts: -------------------------------------------------------------------------------- 1 | let usernames: string[] = ["admin", "user1", "user2", "user3", "user4"]; 2 | 3 | usernames.forEach((username) => { 4 | if (username == "admin") { 5 | console.log("Hello admin, would you like to see a status report?"); 6 | } else { 7 | console.log(`Hello ${username}, thank you for loggin in again.`); 8 | } 9 | }); 10 | -------------------------------------------------------------------------------- /day-17/q50/main.ts: -------------------------------------------------------------------------------- 1 | // Using template literals to define a multiline string 2 | let myIdealDay = `My ideal day would involve: 3 | 1. Waking up early and going for a jog. 4 | 2. Spending a few hours coding on a personal project. 5 | 3. Ending the day by reading a good book.`; 6 | 7 | // Logging the multiline string to the console 8 | console.log(myIdealDay); 9 | -------------------------------------------------------------------------------- /day-21/q62/main.js: -------------------------------------------------------------------------------- 1 | // Filling in the blueprint with an example student 2 | var student = { 3 | name: "Alice", 4 | age: 22, 5 | courses: ["Math", "Science", "History"], 6 | }; 7 | // Showing the student's information 8 | console.log(student); 9 | // We're using the blueprint to make sure our student has a name, age, and list of courses. 10 | -------------------------------------------------------------------------------- /day-27/q79/main.js: -------------------------------------------------------------------------------- 1 | // This sets up an object for a car with specific details 2 | var car = { 3 | make: "Toyota", 4 | model: "Corolla", 5 | year: 2020, 6 | }; 7 | // Accessing and showing the car's model 8 | console.log(car.model); // Outputs: Corolla 9 | // We use dot notation (car.model) to get the model of the car from our object. 10 | -------------------------------------------------------------------------------- /day-27/q79/main.ts: -------------------------------------------------------------------------------- 1 | // This sets up an object for a car with specific details 2 | let car = { 3 | make: "Toyota", 4 | model: "Corolla", 5 | year: 2020, 6 | }; 7 | 8 | // Accessing and showing the car's model 9 | console.log(car.model); // Outputs: Corolla 10 | // We use dot notation (car.model) to get the model of the car from our object. 11 | -------------------------------------------------------------------------------- /day-48/README.md: -------------------------------------------------------------------------------- 1 | # Day-48 of `100-Days-Of-Code` Challenge 2 | 3 | **Question 142:** Create a Promise that resolves with "Hello, World!" after 2 seconds. 4 | 5 | **Question 143:** Show how to use the .then() and .catch() methods to handle Promise resolution and rejection. 6 | 7 | **Question 144:** Explain the use of the Promise.all() method with an example. -------------------------------------------------------------------------------- /day-50/README.md: -------------------------------------------------------------------------------- 1 | # Day-50 of `100-Days-Of-Code` Challenge 2 | 3 | **Question 148:** Demonstrate the use of the setTimeout() function to execute code after a delay. 4 | 5 | **Question 149:** Explain the concept of the event loop in JavaScript with an example. 6 | 7 | **Question 150:** Describe how asynchronous callbacks differ from synchronous code execution. -------------------------------------------------------------------------------- /day-44/q130/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | // In another file where you want to use the add function: 4 | var mathFunction_1 = require("./mathFunction"); 5 | console.log((0, mathFunction_1.add)(2, 3)); // Outputs: 5 6 | // Demonstrates importing the add function from mathFunctions.ts and using it. 7 | -------------------------------------------------------------------------------- /day-46/q136/main.js: -------------------------------------------------------------------------------- 1 | // Demonstrates using console.log() inside a loop to track variable values 2 | for (var i = 1; i <= 5; i++) { 3 | console.log("Iteration ".concat(i, ", i value:, i")); // Logs the current iteration number and the value of i 4 | } 5 | // This loop iterates five times, logging the value of 'i' during each iteration to help with debugging. 6 | -------------------------------------------------------------------------------- /day-11/q33/main.ts: -------------------------------------------------------------------------------- 1 | let numbers: number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9]; 2 | 3 | numbers.forEach((number) => { 4 | let suffix = "th"; 5 | if (number === 1) { 6 | suffix = "st"; 7 | } else if (number === 2) { 8 | suffix = "nd"; 9 | } else if (number === 3) { 10 | suffix = "rd"; 11 | } 12 | console.log(`${number}${suffix}`); 13 | }); 14 | -------------------------------------------------------------------------------- /day-18/q52/main.js: -------------------------------------------------------------------------------- 1 | // Sets up details about a smartphone 2 | var smartphone = { 3 | make: "Samsung", 4 | model: "Galaxy S21", 5 | specs: { 6 | storage: "128GB", 7 | screenSize: "6.2 inches", 8 | batteryLife: "18 hours", 9 | }, 10 | }; 11 | // Shows what we've set up about the smartphone 12 | console.log(smartphone); 13 | -------------------------------------------------------------------------------- /day-22/q66/main.js: -------------------------------------------------------------------------------- 1 | // This function sees if both inputs are true 2 | function checkBothTrue(val1, val2) { 3 | // Only says true if both val1 and val2 are true 4 | return val1 && val2; 5 | } 6 | // Trying it with true and false 7 | console.log(checkBothTrue(true, false)); // Shows false 8 | // It checks two things, but since one is false, the answer is false. 9 | -------------------------------------------------------------------------------- /day-35/q105/main.js: -------------------------------------------------------------------------------- 1 | // This function simulates rolling a dice and returns a number between 1 and 6 2 | function rollDice() { 3 | return Math.floor(Math.random() * 6) + 1; // Calculates a random integer from 1 to 6 4 | } 5 | console.log(rollDice()); // Outputs a random number between 1 and 6 6 | // Here, we mimic the action of rolling a dice and getting a result. 7 | -------------------------------------------------------------------------------- /day-45/q134/main.js: -------------------------------------------------------------------------------- 1 | // Defines a JSON string 2 | var jsonString = '{"name":"Alice","age":30,"city":"Wonderland"}'; 3 | // Parses the JSON string back into a JavaScript object 4 | var person = JSON.parse(jsonString); 5 | console.log(person); // Outputs the original object 6 | // This snippet shows how to take a JSON string and convert it back into a JavaScript object. 7 | -------------------------------------------------------------------------------- /day-46/README.md: -------------------------------------------------------------------------------- 1 | # Day-46 of `100-Days-Of-Code` Challenge 2 | 3 | **Question 136:** Use console.log() to debug and track the value of a variable inside a loop. 4 | 5 | **Question 137:** Implement a try-catch block to handle potential errors in a block of code. 6 | 7 | **Question 138:** Describe how to use breakpoints in browser developer tools to debug JavaScript code. -------------------------------------------------------------------------------- /day-19/q55/main.js: -------------------------------------------------------------------------------- 1 | // Starts with a list of numbers 2 | var numbers = [1, 2, 3, 4, 5]; 3 | // Doubles each number 4 | var doubledNumbers = numbers.map(function (number) { return number * 2; }); 5 | // Shows the new list of doubled numbers 6 | console.log(doubledNumbers); // Output: [2, 4, 6, 8, 10] 7 | // This line takes each number, doubles it, and puts it in a new list. 8 | -------------------------------------------------------------------------------- /day-21/q61/main.ts: -------------------------------------------------------------------------------- 1 | // Making a list (enum) for different types of vehicles 2 | enum VehicleType { 3 | Car, 4 | Truck, 5 | Motorcycle, 6 | } 7 | 8 | // Showing one type of vehicle from the list 9 | console.log(VehicleType.Car); // It shows 0 because enums start counting from 0 10 | // Here, we're just checking what number the Car category got in our list. 11 | -------------------------------------------------------------------------------- /day-35/q103/main.js: -------------------------------------------------------------------------------- 1 | // This function returns a random boolean value 2 | function getRandomBoolean() { 3 | return Math.random() > 0.5; // Returns true if the random number is greater than 0.5 4 | } 5 | console.log(getRandomBoolean()); // Outputs either true or false randomly 6 | // By comparing a random number to 0.5, we effectively get a true or false value randomly. 7 | -------------------------------------------------------------------------------- /day-46/q137/main.ts: -------------------------------------------------------------------------------- 1 | // Demonstrates using a try-catch block to handle errors 2 | try { 3 | // Intentionally cause an error 4 | throw new Error("Something went wrong"); 5 | } catch (error) { 6 | console.log(error.message); // Logs the error message 7 | } 8 | // This code tries to execute a block that throws an error, and the catch block handles the error gracefully. 9 | -------------------------------------------------------------------------------- /day-19/q55/main.ts: -------------------------------------------------------------------------------- 1 | // Starts with a list of numbers 2 | let numbers = [1, 2, 3, 4, 5]; 3 | 4 | // Doubles each number 5 | let doubledNumbers = numbers.map((number) => number * 2); 6 | 7 | // Shows the new list of doubled numbers 8 | console.log(doubledNumbers); // Output: [2, 4, 6, 8, 10] 9 | // This line takes each number, doubles it, and puts it in a new list. 10 | -------------------------------------------------------------------------------- /day-22/q65/main.ts: -------------------------------------------------------------------------------- 1 | // This function finds the leftover of dividing two numbers 2 | function remainder(num1: number, num2: number): number { 3 | // Gives back the leftover of num1 divided by num2 4 | return num1 % num2; 5 | } 6 | 7 | // Trying it with 5 divided by 2 8 | console.log(remainder(5, 2)); // Shows 1 9 | // This tells us the leftover, which is 1 here. 10 | -------------------------------------------------------------------------------- /day-30/q89/main.js: -------------------------------------------------------------------------------- 1 | // This function rounds a number to two decimal places 2 | function roundToTwoDecimalPlaces(num) { 3 | return Number(num.toFixed(2)); // Rounds and converts back to number 4 | } 5 | // Example: Rounding π to two decimal places 6 | console.log(roundToTwoDecimalPlaces(3.14159)); // Outputs 3.14 7 | // π is now rounded off, making it simpler to work with. 8 | -------------------------------------------------------------------------------- /day-33/README.md: -------------------------------------------------------------------------------- 1 | # Day-33 of `100-Days-Of-Code` Challenge 2 | 3 | **Question 97:** Write a function that returns the current date in the format "DD-MM-YYYY". 4 | 5 | **Question 98:** Create a JavaScript snippet that calculates and logs how many days are left until New Year. 6 | 7 | **Question 99:** Generate a date object representing your next birthday and log it to the console. -------------------------------------------------------------------------------- /day-35/q105/main.ts: -------------------------------------------------------------------------------- 1 | // This function simulates rolling a dice and returns a number between 1 and 6 2 | function rollDice(): number { 3 | return Math.floor(Math.random() * 6) + 1; // Calculates a random integer from 1 to 6 4 | } 5 | 6 | console.log(rollDice()); // Outputs a random number between 1 and 6 7 | // Here, we mimic the action of rolling a dice and getting a result. 8 | -------------------------------------------------------------------------------- /day-36/README.md: -------------------------------------------------------------------------------- 1 | # Day-36 of `100-Days-Of-Code` Challenge 2 | 3 | **Question 106:** Determine if a given year is a leap year using comparison operators. 4 | 5 | **Question 107:** Write a condition using logical operators that checks if a number is divisible by both 2 and 3. 6 | 7 | **Question 108:** Compare two strings to check if they are identical, ignoring case sensitivity. -------------------------------------------------------------------------------- /day-47/README.md: -------------------------------------------------------------------------------- 1 | # Day-47 of `100-Days-Of-Code` Challenge 2 | 3 | **Question 139:** List three reserved words in JavaScript and create a valid use case for each. 4 | 5 | **Question 140:** Explain the error that occurs when trying to use a reserved word as a variable name. 6 | 7 | **Question 141:** Discuss the significance of the await reserved word in asynchronous JavaScript. -------------------------------------------------------------------------------- /day-48/q142/main.ts: -------------------------------------------------------------------------------- 1 | // Creates a Promise that resolves with "Hello, World!" after 2 seconds 2 | const helloPromise = new Promise((resolve) => { 3 | setTimeout(() => { 4 | resolve("Hello, World!"); 5 | }, 2000); 6 | }); 7 | 8 | helloPromise.then((message) => console.log(message)); 9 | // After 2 seconds, "Hello, World!" will be logged to the console. 10 | -------------------------------------------------------------------------------- /day-62/README.md: -------------------------------------------------------------------------------- 1 | # Day-62 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-62 Task:** 4 | 5 | First understand what typescript is, and why we need it, then setup typescript using the following guides: 6 | 7 | [TypeScript Introduction in Simple Words](./TS-Intro%20&%20Setup/typescript-intro.md) 8 | 9 | [Setup TypeScript | Step-by-Step](./TS-Intro%20&%20Setup/typescript-setup.md) -------------------------------------------------------------------------------- /day-79/README.md: -------------------------------------------------------------------------------- 1 | # Day-79 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-79 Task:** 4 | 5 | Read the following Articles with interactive video about Basics of Authentication and HTTP Basic Authentication. 6 | 7 | [Basics of Authentication](https://roadmap.sh/guides/basics-of-authentication) 8 | 9 | [HTTP Basic Authentication](https://roadmap.sh/guides/http-basic-authentication) -------------------------------------------------------------------------------- /day-10/q30/main.js: -------------------------------------------------------------------------------- 1 | var usernames = ["admin", "user1", "user2", "user3", "user4"]; 2 | usernames.forEach(function (username) { 3 | if (username == "admin") { 4 | console.log("Hello admin, would you like to see a status report?"); 5 | } 6 | else { 7 | console.log("Hello ".concat(username, ", thank you for loggin in again.")); 8 | } 9 | }); 10 | -------------------------------------------------------------------------------- /day-22/q64/main.js: -------------------------------------------------------------------------------- 1 | // This function mixes a text and a number into one text 2 | function combineStringAndNumber(text, number) { 3 | // Joins the text and number into a single text 4 | return text + number; 5 | } 6 | // Trying it out with "Age: " and 30 7 | console.log(combineStringAndNumber("Age: ", 30)); // Shows "Age: 30" 8 | // Here, we put together the text and number. 9 | -------------------------------------------------------------------------------- /day-30/q88/main.js: -------------------------------------------------------------------------------- 1 | // This function turns text into an actual number 2 | function convertStringToNumber(str) { 3 | return Number(str); // Converts the string to a number 4 | } 5 | // Example: Changing "123" into a real number 6 | console.log(convertStringToNumber("123")); // Outputs the number 123 7 | // Now, "123" is not just text; it's a number we can use in calculations. 8 | -------------------------------------------------------------------------------- /day-45/q134/main.ts: -------------------------------------------------------------------------------- 1 | // Defines a JSON string 2 | const jsonString = '{"name":"Alice","age":30,"city":"Wonderland"}'; 3 | 4 | // Parses the JSON string back into a JavaScript object 5 | const person = JSON.parse(jsonString); 6 | 7 | console.log(person); // Outputs the original object 8 | // This snippet shows how to take a JSON string and convert it back into a JavaScript object. 9 | -------------------------------------------------------------------------------- /day-31/README.md: -------------------------------------------------------------------------------- 1 | # Day-31 of `100-Days-Of-Code` Challenge 2 | 3 | **Question 91:** Create an array of your three favorite fruits and add a new fruit to the end of the array. 4 | 5 | **Question 92:** Write a function to remove the last element from an array and return the removed element. 6 | 7 | **Question 93:** Find the index of "Banana" in an array of fruits and replace it with "Mango". -------------------------------------------------------------------------------- /day-35/q103/main.ts: -------------------------------------------------------------------------------- 1 | // This function returns a random boolean value 2 | function getRandomBoolean(): boolean { 3 | return Math.random() > 0.5; // Returns true if the random number is greater than 0.5 4 | } 5 | 6 | console.log(getRandomBoolean()); // Outputs either true or false randomly 7 | // By comparing a random number to 0.5, we effectively get a true or false value randomly. 8 | -------------------------------------------------------------------------------- /day-37/README.md: -------------------------------------------------------------------------------- 1 | # Day-37 of `100-Days-Of-Code` Challenge 2 | 3 | **Question 109:** Write an if statement that logs "Good Morning" if the current time is before 12 PM. 4 | 5 | **Question 110:** Create a function that assigns a grade (A, B, C, D, F) based on a student's score. 6 | 7 | **Question 111:** Use an if-else-if chain to categorize a person's age group (child, teenager, adult). -------------------------------------------------------------------------------- /day-43/README.md: -------------------------------------------------------------------------------- 1 | # Day-43 of `100-Days-Of-Code` Challenge 2 | 3 | **Question 127:** Convert a traditional function expression to an arrow function. 4 | 5 | **Question 128:** Create an arrow function that takes multiple parameters and returns the product of all parameters. 6 | 7 | **Question 129:** Explain how this behaves differently in arrow functions compared to traditional functions. -------------------------------------------------------------------------------- /day-43/q128/main.ts: -------------------------------------------------------------------------------- 1 | // Arrow function that calculates the product of all its parameters 2 | const multiplyParameters = (...numbers: number[]) => 3 | numbers.reduce((total, number) => total * number, 1); 4 | 5 | console.log(multiplyParameters(2, 3, 4)); // Outputs: 24 6 | // This function uses the rest parameter syntax to take any number of arguments, then multiplies them together. 7 | -------------------------------------------------------------------------------- /day-19/q57/main.js: -------------------------------------------------------------------------------- 1 | // A list of grades 2 | var grades = [88, 94, 72, 99, 53, 77]; 3 | // Calculates the average grade 4 | var averageGrade = grades.reduce(function (total, grade) { return total + grade; }, 0) / grades.length; 5 | // Shows the average grade 6 | console.log(averageGrade); 7 | // First, we add up all the grades. Then, we divide by how many grades there are to get the average. 8 | -------------------------------------------------------------------------------- /day-26/q76/main.js: -------------------------------------------------------------------------------- 1 | // This function adds two numbers and returns the result 2 | function addNumbers(num1, num2) { 3 | // Calculates the sum of num1 and num2 4 | return num1 + num2; 5 | } 6 | // Calling the function with two numbers and logging the result 7 | console.log(addNumbers(5, 7)); // Outputs 12 8 | // Here, we ask our function to add 5 and 7, and it tells us the answer is 12. 9 | -------------------------------------------------------------------------------- /day-28/q82/main.js: -------------------------------------------------------------------------------- 1 | // This function counts how many characters are in a string 2 | function stringLength(str) { 3 | return str.length; // Returns the number of characters in the string 4 | } 5 | // Example: Measuring the length of a name 6 | console.log(stringLength("Alice")); // Outputs: 5 7 | // We're simply asking how long the string "Alice" is, and it tells us there are 5 characters. 8 | -------------------------------------------------------------------------------- /day-38/q112/main.js: -------------------------------------------------------------------------------- 1 | // Creates a new Map to store countries and their capitals 2 | var countries = new Map(); 3 | countries.set("USA", "Washington, D.C."); // Adds USA to the Map 4 | countries.set("France", "Paris"); // Adds France to the Map 5 | countries.set("Japan", "Tokyo"); // Adds Japan to the Map 6 | console.log(countries); 7 | // Logs the Map with the countries and their capitals. 8 | -------------------------------------------------------------------------------- /day-46/q137/main.js: -------------------------------------------------------------------------------- 1 | // Demonstrates using a try-catch block to handle errors 2 | try { 3 | // Intentionally cause an error 4 | throw new Error("Something went wrong"); 5 | } 6 | catch (error) { 7 | console.log(error.message); // Logs the error message 8 | } 9 | // This code tries to execute a block that throws an error, and the catch block handles the error gracefully. 10 | -------------------------------------------------------------------------------- /day-48/q142/main.js: -------------------------------------------------------------------------------- 1 | // Creates a Promise that resolves with "Hello, World!" after 2 seconds 2 | var helloPromise = new Promise(function (resolve) { 3 | setTimeout(function () { 4 | resolve("Hello, World!"); 5 | }, 2000); 6 | }); 7 | helloPromise.then(function (message) { return console.log(message); }); 8 | // After 2 seconds, "Hello, World!" will be logged to the console. 9 | -------------------------------------------------------------------------------- /day-81/README.md: -------------------------------------------------------------------------------- 1 | # Day-81 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-81 Task:** 4 | 5 | Today's task is to learn about: 6 | 7 | - [React Foundation](https://nextjs.org/learn/react-foundations) 8 | - [About React and Next.js](https://nextjs.org/learn/react-foundations/what-is-react-and-nextjs) 9 | - [Rendering User Interfaces (UI)](https://nextjs.org/learn/react-foundations/rendering-ui) -------------------------------------------------------------------------------- /day-30/q88/main.ts: -------------------------------------------------------------------------------- 1 | // This function turns text into an actual number 2 | function convertStringToNumber(str: string): number { 3 | return Number(str); // Converts the string to a number 4 | } 5 | 6 | // Example: Changing "123" into a real number 7 | console.log(convertStringToNumber("123")); // Outputs the number 123 8 | // Now, "123" is not just text; it's a number we can use in calculations. 9 | -------------------------------------------------------------------------------- /day-30/q89/main.ts: -------------------------------------------------------------------------------- 1 | // This function rounds a number to two decimal places 2 | function roundToTwoDecimalPlaces(num: number): number { 3 | return Number(num.toFixed(2)); // Rounds and converts back to number 4 | } 5 | 6 | // Example: Rounding π to two decimal places 7 | console.log(roundToTwoDecimalPlaces(3.14159)); // Outputs 3.14 8 | // π is now rounded off, making it simpler to work with. 9 | -------------------------------------------------------------------------------- /day-41/README.md: -------------------------------------------------------------------------------- 1 | # Day-41 of `100-Days-Of-Code` Challenge 2 | 3 | **Question 121:** Implement a for loop that counts from 1 to 10 but skips number 5 using the continue statement. 4 | 5 | **Question 122:** Use a while loop to count down from 10 to 1 and breaks the loop when it reaches 5. 6 | 7 | **Question 123:** Create a loop that iterates through a string and stops when it finds the first vowel. -------------------------------------------------------------------------------- /day-67/TS-Array/02-Type-Annotations-With-Multidimensional-Arrays.ts: -------------------------------------------------------------------------------- 1 | /************************************************* 2 | * TYPE ANNOTATIONS WITH MULTIDIMENSIONAL ARRAYS * 3 | *************************************************/ 4 | 5 | let arrayOne: number[] = [1, 2, 3, 4, 5]; 6 | let arrayTwo: string[] = ["A", "B", "C"]; 7 | let arrayThree: (string | number)[] = [1, 2, 3, 4, "A", "B", "C"]; 8 | -------------------------------------------------------------------------------- /day-13/q37/main.ts: -------------------------------------------------------------------------------- 1 | function make_shirt(size: string = "large", message: string = "I love TypeScript") { 2 | console.log(`Making a ${size} t-shirt with the message "${message}" printed on it.`); 3 | } 4 | 5 | make_shirt(); // Default large and message 6 | make_shirt("medium"); // Default message, medium size 7 | make_shirt("small", "Dive into Coding"); // Custom message, small size -------------------------------------------------------------------------------- /day-19/q57/main.ts: -------------------------------------------------------------------------------- 1 | // A list of grades 2 | let grades = [88, 94, 72, 99, 53, 77]; 3 | 4 | // Calculates the average grade 5 | let averageGrade = 6 | grades.reduce((total, grade) => total + grade, 0) / grades.length; 7 | 8 | // Shows the average grade 9 | console.log(averageGrade); 10 | // First, we add up all the grades. Then, we divide by how many grades there are to get the average. 11 | -------------------------------------------------------------------------------- /day-22/q66/main.ts: -------------------------------------------------------------------------------- 1 | // This function sees if both inputs are true 2 | function checkBothTrue(val1: boolean, val2: boolean): boolean { 3 | // Only says true if both val1 and val2 are true 4 | return val1 && val2; 5 | } 6 | 7 | // Trying it with true and false 8 | console.log(checkBothTrue(true, false)); // Shows false 9 | // It checks two things, but since one is false, the answer is false. 10 | -------------------------------------------------------------------------------- /day-23/q68/main.js: -------------------------------------------------------------------------------- 1 | // This function multiplies two decimal numbers 2 | function multiplyDecimals(num1, num2) { 3 | // Multiplies the numbers and rounds the result to two decimal places 4 | return Math.round(num1 * num2 * 100) / 100; 5 | } 6 | // Trying it with 0.1 and 0.2 7 | console.log(multiplyDecimals(0.1, 0.2)); // Shows 0.02 8 | // After multiplying, we round to make the result easier to read. 9 | -------------------------------------------------------------------------------- /day-11/q33/main.js: -------------------------------------------------------------------------------- 1 | var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]; 2 | numbers.forEach(function (number) { 3 | var suffix = "th"; 4 | if (number === 1) { 5 | suffix = "st"; 6 | } 7 | else if (number === 2) { 8 | suffix = "nd"; 9 | } 10 | else if (number === 3) { 11 | suffix = "rd"; 12 | } 13 | console.log("".concat(number).concat(suffix)); 14 | }); 15 | -------------------------------------------------------------------------------- /day-28/q82/main.ts: -------------------------------------------------------------------------------- 1 | // This function counts how many characters are in a string 2 | function stringLength(str: string): number { 3 | return str.length; // Returns the number of characters in the string 4 | } 5 | 6 | // Example: Measuring the length of a name 7 | console.log(stringLength("Alice")); // Outputs: 5 8 | // We're simply asking how long the string "Alice" is, and it tells us there are 5 characters. 9 | -------------------------------------------------------------------------------- /day-30/q90/main.js: -------------------------------------------------------------------------------- 1 | // This function creates a random number between 1 and 10 2 | function generateRandomNumber() { 3 | return Math.floor(Math.random() * 10) + 1; // Scales up and rounds down 4 | } 5 | // Example: Getting a random number 6 | console.log(generateRandomNumber()); // Shows a random number between 1 and 10 7 | // Each time you call this, you might get a different number. It's all up to chance! 8 | -------------------------------------------------------------------------------- /day-38/q112/main.ts: -------------------------------------------------------------------------------- 1 | // Creates a new Map to store countries and their capitals 2 | const countries = new Map(); 3 | countries.set("USA", "Washington, D.C."); // Adds USA to the Map 4 | countries.set("France", "Paris"); // Adds France to the Map 5 | countries.set("Japan", "Tokyo"); // Adds Japan to the Map 6 | 7 | console.log(countries); 8 | // Logs the Map with the countries and their capitals. 9 | -------------------------------------------------------------------------------- /day-44/README.md: -------------------------------------------------------------------------------- 1 | # Day-44 of `100-Days-Of-Code` Challenge 2 | 3 | **Question 130:** Explain how to export a function from one JavaScript file and import it into another file. 4 | 5 | **Question 131:** Create two modules; one that exports a class, and another that imports the class and creates an instance. 6 | 7 | **Question 132:** Discuss the difference between default and named exports in JavaScript modules. -------------------------------------------------------------------------------- /day-14/q40/main.js: -------------------------------------------------------------------------------- 1 | function make_album(artist, title, tracks) { 2 | var album = { artist: artist, title: title }; 3 | if (tracks) { 4 | album["tracks"] = tracks; 5 | } 6 | return album; 7 | } 8 | console.log(make_album("Artist One", "The First Album")); 9 | console.log(make_album("Artist Two", "The Second Album")); 10 | console.log(make_album("Artist Three", "The Third Album", 12)); 11 | -------------------------------------------------------------------------------- /day-15/q44/main.js: -------------------------------------------------------------------------------- 1 | function make_sandwich() { 2 | var items = []; 3 | for (var _i = 0; _i < arguments.length; _i++) { 4 | items[_i] = arguments[_i]; 5 | } 6 | console.log("Making a sandwich with: ".concat(items.join(", "), ".")); 7 | } 8 | make_sandwich("ham", "cheese"); 9 | make_sandwich("turkey", "lettuce", "tomato"); 10 | make_sandwich("avocado", "sprouts", "mustard", "mayo"); 11 | -------------------------------------------------------------------------------- /day-22/q64/main.ts: -------------------------------------------------------------------------------- 1 | // This function mixes a text and a number into one text 2 | function combineStringAndNumber(text: string, number: number): string { 3 | // Joins the text and number into a single text 4 | return text + number; 5 | } 6 | 7 | // Trying it out with "Age: " and 30 8 | console.log(combineStringAndNumber("Age: ", 30)); // Shows "Age: 30" 9 | // Here, we put together the text and number. 10 | -------------------------------------------------------------------------------- /day-29/q85/main.js: -------------------------------------------------------------------------------- 1 | // This function finds where "code" first shows up in a text 2 | function findCodePosition(str) { 3 | return str.indexOf("code"); // Looks for "code" and tells where it found it 4 | } 5 | // Example: Searching within a sentence 6 | console.log(findCodePosition("Learn to code with JavaScript")); // Outputs the start position of "code" 7 | // It tells us the position number where "code" starts. 8 | -------------------------------------------------------------------------------- /day-32/q94/main.js: -------------------------------------------------------------------------------- 1 | // Defines an array with some words 2 | var words = ["Hello", "World", "TypeScript", "JavaScript"]; 3 | // Uses .map() to create a new array with the length of each word 4 | var lengths = words.map(function (word) { return word.length; }); 5 | console.log(lengths); // Outputs: [5, 5, 10, 10] 6 | // Each number in the new array represents the length of the corresponding word in the original array. 7 | -------------------------------------------------------------------------------- /day-39/README.md: -------------------------------------------------------------------------------- 1 | # Day-39 of `100-Days-Of-Code` Challenge 2 | 3 | **Question 115:** Use a switch statement to log the days of the week based on a number (1-7). 4 | 5 | **Question 116:** Create a switch case that matches several cases to the same code block, representing seasons. 6 | 7 | **Question 117:** Implement a switch statement that evaluates an expression and uses the default case if none of the cases match. -------------------------------------------------------------------------------- /day-14/q40/main.ts: -------------------------------------------------------------------------------- 1 | function make_album(artist: string, title: string, tracks?: number) { 2 | let album = { artist, title }; 3 | if (tracks) { 4 | album["tracks"] = tracks; 5 | } 6 | return album; 7 | } 8 | 9 | console.log(make_album("Artist One", "The First Album")); 10 | console.log(make_album("Artist Two", "The Second Album")); 11 | console.log(make_album("Artist Three", "The Third Album", 12)); 12 | -------------------------------------------------------------------------------- /day-17/q49/main.ts: -------------------------------------------------------------------------------- 1 | // Defines a function that accepts multiple hobbies as arguments 2 | function logHobbies(...hobbies: string[]) { 3 | // Loops through each hobby in the array 4 | hobbies.forEach((hobby) => { 5 | // Logs a statement for each hobby 6 | console.log(`I enjoy ${hobby}.`); 7 | }); 8 | } 9 | 10 | // Calls the function with three hobbies 11 | logHobbies("reading", "coding", "cycling"); 12 | -------------------------------------------------------------------------------- /day-19/README.md: -------------------------------------------------------------------------------- 1 | # Day-19 of `100-Days-Of-Code` Challenge 2 | 3 | **Q55** - Double Numbers in an Array: Make a list of numbers. Then, use a trick to make a new list where each number is twice its original value. 4 | 5 | **Q56** - Keep Only Strings: Given a mix of different types of items, make a new list that has only the words. 6 | 7 | **Q57** - Find the Average Grade: Given a list of grades, calculate the average grade. -------------------------------------------------------------------------------- /day-19/q56/main.js: -------------------------------------------------------------------------------- 1 | // A mixed bag of items 2 | var mixedArray = [1, "apple", 2, "banana", true, "carrot"]; 3 | // Picks out only the words 4 | var stringsArray = mixedArray.filter(function (item) { return typeof item === "string"; }); 5 | // Shows the list of just words 6 | console.log(stringsArray); // Output: ["apple", "banana", "carrot"] 7 | // This line checks each item: if it's a word, it goes into the new list. 8 | -------------------------------------------------------------------------------- /day-19/q56/main.ts: -------------------------------------------------------------------------------- 1 | // A mixed bag of items 2 | let mixedArray = [1, "apple", 2, "banana", true, "carrot"]; 3 | 4 | // Picks out only the words 5 | let stringsArray = mixedArray.filter((item) => typeof item === "string"); 6 | 7 | // Shows the list of just words 8 | console.log(stringsArray); // Output: ["apple", "banana", "carrot"] 9 | // This line checks each item: if it's a word, it goes into the new list. 10 | -------------------------------------------------------------------------------- /day-30/q90/main.ts: -------------------------------------------------------------------------------- 1 | // This function creates a random number between 1 and 10 2 | function generateRandomNumber(): number { 3 | return Math.floor(Math.random() * 10) + 1; // Scales up and rounds down 4 | } 5 | 6 | // Example: Getting a random number 7 | console.log(generateRandomNumber()); // Shows a random number between 1 and 10 8 | // Each time you call this, you might get a different number. It's all up to chance! 9 | -------------------------------------------------------------------------------- /day-32/README.md: -------------------------------------------------------------------------------- 1 | # Day-32 of `100-Days-Of-Code` Challenge 2 | 3 | **Question 94:** Use the .map() method to create a new array that contains the length of each word from an array of words. 4 | 5 | **Question 95:** Write a function that uses the .filter() method to return an array of numbers greater than 10. 6 | 7 | **Question 96:** Demonstrate how to use the .reduce() method to calculate the sum of all numbers in an array. -------------------------------------------------------------------------------- /day-41/q122/main.js: -------------------------------------------------------------------------------- 1 | // Initializes the counter at 10 2 | var counter = 10; 3 | // This while loop counts down from 10 to 1 and stops at 5 4 | while (counter > 0) { 5 | if (counter === 5) { 6 | break; // Exits the loop when counter reaches 5 7 | } 8 | console.log(counter); 9 | counter--; // Decrements the counter 10 | } 11 | // Logs the countdown from 10 but stops abruptly when it hits 5. 12 | -------------------------------------------------------------------------------- /day-41/q122/main.ts: -------------------------------------------------------------------------------- 1 | // Initializes the counter at 10 2 | let counter: number = 10; 3 | // This while loop counts down from 10 to 1 and stops at 5 4 | while (counter > 0) { 5 | if (counter === 5) { 6 | break; // Exits the loop when counter reaches 5 7 | } 8 | console.log(counter); 9 | counter--; // Decrements the counter 10 | } 11 | // Logs the countdown from 10 but stops abruptly when it hits 5. 12 | -------------------------------------------------------------------------------- /day-17/q51/main.js: -------------------------------------------------------------------------------- 1 | // Original function for calculating the area of a rectangle 2 | function calculateArea(width, height) { 3 | return width * height; 4 | } 5 | // Refactored into an arrow function 6 | var calculateAreaArrow = function (width, height) { 7 | return width * height; 8 | }; 9 | // Example usage of the arrow function 10 | console.log(calculateAreaArrow(5, 7)); // Logs the area of the rectangle 11 | -------------------------------------------------------------------------------- /day-26/q76/main.ts: -------------------------------------------------------------------------------- 1 | // This function adds two numbers and returns the result 2 | function addNumbers(num1: number, num2: number): number { 3 | // Calculates the sum of num1 and num2 4 | return num1 + num2; 5 | } 6 | 7 | // Calling the function with two numbers and logging the result 8 | console.log(addNumbers(5, 7)); // Outputs 12 9 | // Here, we ask our function to add 5 and 7, and it tells us the answer is 12. 10 | -------------------------------------------------------------------------------- /day-32/q94/main.ts: -------------------------------------------------------------------------------- 1 | // Defines an array with some words 2 | const words: string[] = ["Hello", "World", "TypeScript", "JavaScript"]; 3 | // Uses .map() to create a new array with the length of each word 4 | const lengths: number[] = words.map((word) => word.length); 5 | 6 | console.log(lengths); // Outputs: [5, 5, 10, 10] 7 | // Each number in the new array represents the length of the corresponding word in the original array. 8 | -------------------------------------------------------------------------------- /day-36/q106/main.js: -------------------------------------------------------------------------------- 1 | // This function checks if a year is a leap year 2 | function isLeapYear(year) { 3 | // Checks the conditions for a leap year 4 | return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; 5 | } 6 | console.log(isLeapYear(2020)); // Outputs: true 7 | console.log(isLeapYear(1900)); // Outputs: false 8 | // By using comparison operators, we can easily determine if a year is a leap year or not. 9 | -------------------------------------------------------------------------------- /day-45/q133/main.js: -------------------------------------------------------------------------------- 1 | // Defines a JavaScript object 2 | var person = { 3 | name: "Alice", 4 | age: 30, 5 | city: "Wonderland", 6 | }; 7 | // Converts the object into a JSON string 8 | var jsonString = JSON.stringify(person); 9 | console.log(jsonString); // Outputs: {"name":"Alice","age":30,"city":"Wonderland"} 10 | // Demonstrates converting an object to a JSON string, making it easy to store or transmit. 11 | -------------------------------------------------------------------------------- /day-37/q110/main.ts: -------------------------------------------------------------------------------- 1 | function assignGrade(score: number): string { 2 | if (score >= 90) { 3 | return "A"; 4 | } else if (score >= 80) { 5 | return "B"; 6 | } else if (score >= 70) { 7 | return "C"; 8 | } else if (score >= 60) { 9 | return "D"; 10 | } else { 11 | return "F"; 12 | } 13 | } 14 | 15 | console.log(assignGrade(85)); // Outputs: B 16 | console.log(assignGrade(55)); // Outputs: F 17 | -------------------------------------------------------------------------------- /day-38/README.md: -------------------------------------------------------------------------------- 1 | # Day-38 of `100-Days-Of-Code` Challenge 2 | 3 | **Question 112:** Create a Map that stores the names of countries as keys and their capitals as values. Add three countries to the Map. 4 | 5 | **Question 113:** Write a function that checks if a Map contains a key for "Canada" and logs the capital if it exists. 6 | 7 | **Question 114:** Iterate over a Map of student IDs and names, and log each pair to the console. -------------------------------------------------------------------------------- /day-40/q120/main.ts: -------------------------------------------------------------------------------- 1 | // Defines an array of favorite movies 2 | const favoriteMovies: string[] = [ 3 | "Inception", 4 | "The Matrix", 5 | "Interstellar", 6 | "The Prestige", 7 | ]; 8 | // Uses a for...of loop to iterate through favoriteMovies 9 | for (const movie of favoriteMovies) { 10 | console.log(movie); // Logs each movie name 11 | } 12 | // Each movie in the array is logged to the console, one at a time. 13 | -------------------------------------------------------------------------------- /day-15/q45/main.ts: -------------------------------------------------------------------------------- 1 | function make_car( 2 | manufacturer: string, 3 | model: string, 4 | ...options: [string, any][] 5 | ) { 6 | let car = { manufacturer, model }; 7 | options.forEach(([key, value]) => (car[key] = value)); 8 | return car; 9 | } 10 | 11 | console.log(make_car("Toyota", "Carolla", ["color", "red"], ["year", 2020])); 12 | console.log(make_car("Ford", "Fiesta", ["color", "blue"], ["sunroof", true])); 13 | -------------------------------------------------------------------------------- /day-23/q67/main.js: -------------------------------------------------------------------------------- 1 | // This function adds a number and a string that represents a number 2 | function addNumberAndString(number1, numberString) { 3 | // Converts the string to a number and adds it to the first number 4 | return number1 + Number(numberString); 5 | } 6 | // Trying it with 10 and "5" 7 | console.log(addNumberAndString(10, "5")); // Shows 15 8 | // The string "5" is turned into the number 5, and then added to 10. 9 | -------------------------------------------------------------------------------- /day-29/q85/main.ts: -------------------------------------------------------------------------------- 1 | // This function finds where "code" first shows up in a text 2 | function findCodePosition(str: string): number { 3 | return str.indexOf("code"); // Looks for "code" and tells where it found it 4 | } 5 | 6 | // Example: Searching within a sentence 7 | console.log(findCodePosition("Learn to code with JavaScript")); // Outputs the start position of "code" 8 | // It tells us the position number where "code" starts. 9 | -------------------------------------------------------------------------------- /day-42/README.md: -------------------------------------------------------------------------------- 1 | # Day-42 of `100-Days-Of-Code` Challenge 2 | 3 | **Question 124:** Create a function inside an object that returns the object's own name property using the this keyword. 4 | 5 | **Question 125:** Modify a method in an object to use the this keyword to access another property in the same object. 6 | 7 | **Question 126:** Explain how the this keyword changes its value when used inside a nested function within a method. -------------------------------------------------------------------------------- /day-43/q127/main.js: -------------------------------------------------------------------------------- 1 | // Traditional function expression 2 | var traditionalFunction = function (a, b) { 3 | return a + b; 4 | }; 5 | // Converted to arrow function 6 | var arrowFunction = function (a, b) { return a + b; }; 7 | console.log(traditionalFunction(5, 3)); // Outputs: 8 8 | console.log(arrowFunction(5, 3)); // Outputs: 8 9 | // Demonstrates the conversion of a traditional function expression to an arrow function. 10 | -------------------------------------------------------------------------------- /day-43/q127/main.ts: -------------------------------------------------------------------------------- 1 | // Traditional function expression 2 | const traditionalFunction = function (a, b) { 3 | return a + b; 4 | }; 5 | 6 | // Converted to arrow function 7 | const arrowFunction = (a, b) => a + b; 8 | 9 | console.log(traditionalFunction(5, 3)); // Outputs: 8 10 | console.log(arrowFunction(5, 3)); // Outputs: 8 11 | // Demonstrates the conversion of a traditional function expression to an arrow function. 12 | -------------------------------------------------------------------------------- /day-45/q133/main.ts: -------------------------------------------------------------------------------- 1 | // Defines a JavaScript object 2 | const person = { 3 | name: "Alice", 4 | age: 30, 5 | city: "Wonderland", 6 | }; 7 | 8 | // Converts the object into a JSON string 9 | const jsonString = JSON.stringify(person); 10 | 11 | console.log(jsonString); // Outputs: {"name":"Alice","age":30,"city":"Wonderland"} 12 | // Demonstrates converting an object to a JSON string, making it easy to store or transmit. 13 | -------------------------------------------------------------------------------- /day-67/TS-Array/01-Type-Annotations-With-Arrays.ts: -------------------------------------------------------------------------------- 1 | /******************************** 2 | * TYPE ANNOTATIONS WITH ARRAYS * 3 | ********************************/ 4 | 5 | // Annotating an array of strings 6 | let fruits: string[] = ["apple", "banana", "cherry"]; 7 | 8 | // Using a loop to process each element in the array 9 | for (let i = 0; i < fruits.length; i++) { 10 | console.log(`Fruit: ${fruits[i].toUpperCase()}`); 11 | } -------------------------------------------------------------------------------- /day-23/q68/main.ts: -------------------------------------------------------------------------------- 1 | // This function multiplies two decimal numbers 2 | function multiplyDecimals(num1: number, num2: number): number { 3 | // Multiplies the numbers and rounds the result to two decimal places 4 | return Math.round(num1 * num2 * 100) / 100; 5 | } 6 | 7 | // Trying it with 0.1 and 0.2 8 | console.log(multiplyDecimals(0.1, 0.2)); // Shows 0.02 9 | // After multiplying, we round to make the result easier to read. 10 | -------------------------------------------------------------------------------- /day-06/q16/main.js: -------------------------------------------------------------------------------- 1 | var guests = ["Albert Einstein", "Marie Curie", "Leonardo da Vinci"]; 2 | console.log("Great news! I found a bigger dinner table!"); 3 | // Adding more guests 4 | guests.unshift("Isaac Newton"); 5 | guests.splice(guests.length / 2, 0, "Charles Darwin"); 6 | guests.push("Ada Lovelace"); 7 | guests.forEach(function (guest) { 8 | console.log("Dear ".concat(guest, ", would you like to join me for dinner?")); 9 | }); 10 | -------------------------------------------------------------------------------- /day-06/q16/main.ts: -------------------------------------------------------------------------------- 1 | let guests: string[] = ["Albert Einstein", "Marie Curie", "Leonardo da Vinci"]; 2 | console.log("Great news! I found a bigger dinner table!"); 3 | 4 | // Adding more guests 5 | guests.unshift("Isaac Newton"); 6 | guests.splice(guests.length / 2, 0, "Charles Darwin"); 7 | guests.push("Ada Lovelace"); 8 | 9 | guests.forEach(guest => { 10 | console.log(`Dear ${guest}, would you like to join me for dinner?`); 11 | }); -------------------------------------------------------------------------------- /day-20/README.md: -------------------------------------------------------------------------------- 1 | # Day-20 of `100-Days-Of-Code` Challenge 2 | 3 | **Q58** - Write a simple program that can take lots of scores and find their average. 4 | 5 | **Q59** - Add a Special Number: Make a program that creates custom adders. These adders can add a specific number to any other number you give them later. 6 | 7 | **Q60** - Self-Running User Profile: Create a quick, self-setup profile for a user that can tell you the user's name and age. -------------------------------------------------------------------------------- /day-32/q95/main.js: -------------------------------------------------------------------------------- 1 | // This function filters an array, keeping only numbers greater than 10 2 | function filterGreaterThanTen(numbers) { 3 | return numbers.filter(function (number) { return number > 10; }); 4 | } 5 | // Example: Filtering an array of numbers 6 | var numbers = [5, 10, 15, 20, 25]; 7 | console.log(filterGreaterThanTen(numbers)); // Outputs: [15, 20, 25] 8 | // The new array contains only the numbers that are greater than 10. 9 | -------------------------------------------------------------------------------- /day-42/q124/main.js: -------------------------------------------------------------------------------- 1 | // Defines an object with a name property and a method to return its name 2 | var person = { 3 | name: "Alice", 4 | getName: function () { 5 | return this.name; // Uses 'this' to refer to the object itself and return its 'name' property 6 | }, 7 | }; 8 | console.log(person.getName()); // Outputs: Alice 9 | // This method correctly identifies and returns the object's 'name' property using 'this'. 10 | -------------------------------------------------------------------------------- /day-42/q124/main.ts: -------------------------------------------------------------------------------- 1 | // Defines an object with a name property and a method to return its name 2 | const person = { 3 | name: "Alice", 4 | getName: function () { 5 | return this.name; // Uses 'this' to refer to the object itself and return its 'name' property 6 | }, 7 | }; 8 | 9 | console.log(person.getName()); // Outputs: Alice 10 | // This method correctly identifies and returns the object's 'name' property using 'this'. 11 | -------------------------------------------------------------------------------- /day-29/q86/main.js: -------------------------------------------------------------------------------- 1 | // This function checks if a sentence has "JavaScript" in it 2 | function hasJavaScript(str) { 3 | return str.includes("JavaScript"); // Checks for "JavaScript" and returns true or false 4 | } 5 | // Example: Seeing if a text mentions JavaScript 6 | console.log(hasJavaScript("I love coding in JavaScript!")); // Outputs true or false based on the check 7 | // It simply says true if "JavaScript" is there, or false if it's not. 8 | -------------------------------------------------------------------------------- /day-17/q51/main.ts: -------------------------------------------------------------------------------- 1 | // Original function for calculating the area of a rectangle 2 | function calculateArea(width: number, height: number): number { 3 | return width * height; 4 | } 5 | 6 | // Refactored into an arrow function 7 | let calculateAreaArrow = (width: number, height: number): number => 8 | width * height; 9 | 10 | // Example usage of the arrow function 11 | console.log(calculateAreaArrow(5, 7)); // Logs the area of the rectangle 12 | -------------------------------------------------------------------------------- /day-29/q87/main.js: -------------------------------------------------------------------------------- 1 | // This function takes out the first 10 characters from any text 2 | function extractFirstTenChars(str) { 3 | return str.substring(0, 10); // Gets characters from start to position 10 4 | } 5 | // Example: Taking the first 10 characters of a sentence 6 | console.log(extractFirstTenChars("Hello, JavaScript world!")); // Shows the first 10 characters 7 | // It gives us a smaller piece of the original text, just the beginning part. 8 | -------------------------------------------------------------------------------- /day-32/q96/main.js: -------------------------------------------------------------------------------- 1 | // This function calculates the sum of all numbers in an array 2 | function calculateSum(numbers) { 3 | return numbers.reduce(function (accumulator, current) { return accumulator + current; }, 0); 4 | } 5 | // Example: Calculating the sum of an array of numbers 6 | var numbers = [1, 2, 3, 4, 5]; 7 | console.log(calculateSum(numbers)); // Outputs: 15 8 | // It adds up all the numbers in the array, resulting in a single sum value. 9 | -------------------------------------------------------------------------------- /day-36/q106/main.ts: -------------------------------------------------------------------------------- 1 | // This function checks if a year is a leap year 2 | function isLeapYear(year: number): boolean { 3 | // Checks the conditions for a leap year 4 | return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; 5 | } 6 | 7 | console.log(isLeapYear(2020)); // Outputs: true 8 | console.log(isLeapYear(1900)); // Outputs: false 9 | // By using comparison operators, we can easily determine if a year is a leap year or not. 10 | -------------------------------------------------------------------------------- /day-36/q107/main.js: -------------------------------------------------------------------------------- 1 | // This function checks if a number is divisible by both 2 and 3 2 | function isDivisibleByTwoAndThree(number) { 3 | // Uses the modulo operator to check for no remainder 4 | return number % 2 === 0 && number % 3 === 0; 5 | } 6 | console.log(isDivisibleByTwoAndThree(12)); // Outputs: true 7 | console.log(isDivisibleByTwoAndThree(14)); // Outputs: false 8 | // Logical operators help us verify the number's divisibility by both 2 and 3. 9 | -------------------------------------------------------------------------------- /day-49/q146/main.js: -------------------------------------------------------------------------------- 1 | // This array of numbers will be filtered 2 | var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; 3 | // Uses .filter() with a callback function to filter out numbers greater than 5 4 | var filteredNumbers = numbers.filter(function (number) { return number > 5; }); 5 | console.log(filteredNumbers); // Outputs: [6, 7, 8, 9, 10] 6 | // The callback function here checks each number, and .filter() creates a new array with numbers that meet the criteria. 7 | -------------------------------------------------------------------------------- /day-13/q37/main.js: -------------------------------------------------------------------------------- 1 | function make_shirt(size, message) { 2 | if (size === void 0) { size = "large"; } 3 | if (message === void 0) { message = "I love TypeScript"; } 4 | console.log("Making a ".concat(size, " t-shirt with the message \"").concat(message, "\" printed on it.")); 5 | } 6 | make_shirt(); // Default large and message 7 | make_shirt("medium"); // Default message, medium size 8 | make_shirt("small", "Dive into Coding"); // Custom message, small size 9 | -------------------------------------------------------------------------------- /day-23/q67/main.ts: -------------------------------------------------------------------------------- 1 | // This function adds a number and a string that represents a number 2 | function addNumberAndString(number1: number, numberString: string): number { 3 | // Converts the string to a number and adds it to the first number 4 | return number1 + Number(numberString); 5 | } 6 | 7 | // Trying it with 10 and "5" 8 | console.log(addNumberAndString(10, "5")); // Shows 15 9 | // The string "5" is turned into the number 5, and then added to 10. 10 | -------------------------------------------------------------------------------- /day-29/q86/main.ts: -------------------------------------------------------------------------------- 1 | // This function checks if a sentence has "JavaScript" in it 2 | function hasJavaScript(str: string): boolean { 3 | return str.includes("JavaScript"); // Checks for "JavaScript" and returns true or false 4 | } 5 | 6 | // Example: Seeing if a text mentions JavaScript 7 | console.log(hasJavaScript("I love coding in JavaScript!")); // Outputs true or false based on the check 8 | // It simply says true if "JavaScript" is there, or false if it's not. 9 | -------------------------------------------------------------------------------- /day-29/q87/main.ts: -------------------------------------------------------------------------------- 1 | // This function takes out the first 10 characters from any text 2 | function extractFirstTenChars(str: string): string { 3 | return str.substring(0, 10); // Gets characters from start to position 10 4 | } 5 | 6 | // Example: Taking the first 10 characters of a sentence 7 | console.log(extractFirstTenChars("Hello, JavaScript world!")); // Shows the first 10 characters 8 | // It gives us a smaller piece of the original text, just the beginning part. 9 | -------------------------------------------------------------------------------- /day-32/q95/main.ts: -------------------------------------------------------------------------------- 1 | // This function filters an array, keeping only numbers greater than 10 2 | function filterGreaterThanTen(numbers: number[]): number[] { 3 | return numbers.filter((number) => number > 10); 4 | } 5 | 6 | // Example: Filtering an array of numbers 7 | const numbers: number[] = [5, 10, 15, 20, 25]; 8 | console.log(filterGreaterThanTen(numbers)); // Outputs: [15, 20, 25] 9 | // The new array contains only the numbers that are greater than 10. 10 | -------------------------------------------------------------------------------- /day-38/q114/main.js: -------------------------------------------------------------------------------- 1 | // Creates a Map to store student IDs (keys) and names (values) 2 | var students = new Map(); 3 | students.set(1, "Alice"); 4 | students.set(2, "Bob"); 5 | students.set(3, "Charlie"); 6 | // Iterates over the Map and logs each student ID and name 7 | students.forEach(function (name, id) { 8 | console.log("Student ID: ".concat(id, ", Name: ").concat(name)); 9 | }); 10 | // This loop goes through each student and logs their ID and name. 11 | -------------------------------------------------------------------------------- /day-38/q114/main.ts: -------------------------------------------------------------------------------- 1 | // Creates a Map to store student IDs (keys) and names (values) 2 | const students = new Map(); 3 | students.set(1, "Alice"); 4 | students.set(2, "Bob"); 5 | students.set(3, "Charlie"); 6 | 7 | // Iterates over the Map and logs each student ID and name 8 | students.forEach((name, id) => { 9 | console.log(`Student ID: ${id}, Name: ${name}`); 10 | }); 11 | // This loop goes through each student and logs their ID and name. 12 | -------------------------------------------------------------------------------- /day-66/TS-Type-System-Concepts/01-Union-Types.ts: -------------------------------------------------------------------------------- 1 | /*************** 2 | * UNION TYPES * 3 | ***************/ 4 | 5 | let myVar: string | number; 6 | 7 | myVar = "Hello"; // Valid assignment 8 | console.log(myVar) 9 | 10 | myVar = 42; // Valid assignment 11 | console.log(myVar) 12 | 13 | 14 | // Uncommenting the line below would result in a TypeScript error 15 | // myVar = true; // Error: Type 'boolean' is not assignable to type 'string | number'. 16 | -------------------------------------------------------------------------------- /day-01/README.md: -------------------------------------------------------------------------------- 1 | # Day-01 of `100-Days-Of-Code` Challenge 2 | 3 | **Q1** - Install Node.js, TypeScript and VS Code on your computer. 4 | 5 | **Q2** - Personal Message: Store a person’s name in a variable, and print a message to that person. Your message should be simple, such as, “Hello Eric, would you like to learn some Python today?” 6 | 7 | **Q3** - Name Cases: Store a person’s name in a variable, and then print that person’s name in lowercase, uppercase, and titlecase. -------------------------------------------------------------------------------- /day-37/q110/main.js: -------------------------------------------------------------------------------- 1 | function assignGrade(score) { 2 | if (score >= 90) { 3 | return "A"; 4 | } 5 | else if (score >= 80) { 6 | return "B"; 7 | } 8 | else if (score >= 70) { 9 | return "C"; 10 | } 11 | else if (score >= 60) { 12 | return "D"; 13 | } 14 | else { 15 | return "F"; 16 | } 17 | } 18 | console.log(assignGrade(85)); // Outputs: B 19 | console.log(assignGrade(55)); // Outputs: F 20 | -------------------------------------------------------------------------------- /day-52/README.md: -------------------------------------------------------------------------------- 1 | # Day-52 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-52 Task:** 4 | Read the following article: 5 | [An Introduction to JavaScript](https://javascript.info/intro) 6 | 7 | Let’s see what’s so special about JavaScript, what we can achieve with it, and what other technologies play well with it. This article will give you a brief overview of JavaScript and its capabilities. It’s a great starting point for beginners and a good refresher for experienced developers. -------------------------------------------------------------------------------- /day-10/q28/main.ts: -------------------------------------------------------------------------------- 1 | let age: number = 25; 2 | 3 | if (age < 2) { 4 | console.log("The person is a baby."); 5 | } else if (age < 4) { 6 | console.log("The person is a toddler."); 7 | } else if (age < 13) { 8 | console.log("The person is a kid."); 9 | } else if (age < 20) { 10 | console.log("The person is a teenager."); 11 | } else if (age < 65) { 12 | console.log("The person is an adult."); 13 | } else { 14 | console.log("The person is an elder."); 15 | } 16 | -------------------------------------------------------------------------------- /day-32/q96/main.ts: -------------------------------------------------------------------------------- 1 | // This function calculates the sum of all numbers in an array 2 | function calculateSum(numbers: number[]): number { 3 | return numbers.reduce((accumulator, current) => accumulator + current, 0); 4 | } 5 | 6 | // Example: Calculating the sum of an array of numbers 7 | const numbers: number[] = [1, 2, 3, 4, 5]; 8 | console.log(calculateSum(numbers)); // Outputs: 15 9 | // It adds up all the numbers in the array, resulting in a single sum value. 10 | -------------------------------------------------------------------------------- /day-49/q146/main.ts: -------------------------------------------------------------------------------- 1 | // This array of numbers will be filtered 2 | const numbers: number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; 3 | 4 | // Uses .filter() with a callback function to filter out numbers greater than 5 5 | const filteredNumbers: number[] = numbers.filter((number) => number > 5); 6 | 7 | console.log(filteredNumbers); // Outputs: [6, 7, 8, 9, 10] 8 | // The callback function here checks each number, and .filter() creates a new array with numbers that meet the criteria. 9 | -------------------------------------------------------------------------------- /day-18/q54/main.js: -------------------------------------------------------------------------------- 1 | // A way to make a flexible list 2 | function createObjectWithDynamicKey(key, value) { 3 | var dynamicObject = {}; 4 | // Setting up a section in the list with a changeable name 5 | dynamicObject[key] = value; 6 | return dynamicObject; 7 | } 8 | // Using the flexible list setup for a user's preference 9 | var userPreference = createObjectWithDynamicKey("theme", "dark"); 10 | // Showing the user's choice 11 | console.log(userPreference); 12 | -------------------------------------------------------------------------------- /day-24/q70/main.ts: -------------------------------------------------------------------------------- 1 | // This function prints numbers from 1 to 5 using a loop 2 | function printNumbersWithLet() { 3 | for (let i = 1; i <= 5; i++) { 4 | // Uses let for loop variable i 5 | console.log(i); // Logs numbers 1 through 5 6 | } 7 | // i is not accessible here, outside the loop, because it's defined with let 8 | } 9 | 10 | printNumbersWithLet(); 11 | // This shows that let limits i to the loop, preventing errors from using i where it's not intended. 12 | -------------------------------------------------------------------------------- /day-14/q42/main.js: -------------------------------------------------------------------------------- 1 | var magicians = ["Alice", "David", "Chris"]; 2 | function show_magicians(magicians) { 3 | magicians.forEach(function (magician) { 4 | console.log(magician); 5 | }); 6 | } 7 | function make_great(magicians) { 8 | for (var i = 0; i < magicians.length; i++) { 9 | magicians[i] = magicians[i] + " the Great"; 10 | } 11 | } 12 | make_great(magicians); // Modifies the original array 13 | show_magicians(magicians); // Shows modified names 14 | -------------------------------------------------------------------------------- /day-25/q73/main.ts: -------------------------------------------------------------------------------- 1 | // This function shows how to assign and update variable values 2 | function updateVariable() { 3 | let number = 10; // Initially assigns the value 10 4 | console.log("Initial value:", number); // Logs the initial value 5 | number = 20; // Updates the value to 20 6 | console.log("Updated value:", number); // Logs the updated value 7 | } 8 | 9 | updateVariable(); 10 | // We assign a value to a variable and then update it, showing how values can change. 11 | -------------------------------------------------------------------------------- /day-36/q107/main.ts: -------------------------------------------------------------------------------- 1 | // This function checks if a number is divisible by both 2 and 3 2 | function isDivisibleByTwoAndThree(number: number): boolean { 3 | // Uses the modulo operator to check for no remainder 4 | return number % 2 === 0 && number % 3 === 0; 5 | } 6 | 7 | console.log(isDivisibleByTwoAndThree(12)); // Outputs: true 8 | console.log(isDivisibleByTwoAndThree(14)); // Outputs: false 9 | // Logical operators help us verify the number's divisibility by both 2 and 3. 10 | -------------------------------------------------------------------------------- /day-24/q70/main.js: -------------------------------------------------------------------------------- 1 | // This function prints numbers from 1 to 5 using a loop 2 | function printNumbersWithLet() { 3 | for (var i = 1; i <= 5; i++) { 4 | // Uses let for loop variable i 5 | console.log(i); // Logs numbers 1 through 5 6 | } 7 | // i is not accessible here, outside the loop, because it's defined with let 8 | } 9 | printNumbersWithLet(); 10 | // This shows that let limits i to the loop, preventing errors from using i where it's not intended. 11 | -------------------------------------------------------------------------------- /day-25/q73/main.js: -------------------------------------------------------------------------------- 1 | // This function shows how to assign and update variable values 2 | function updateVariable() { 3 | var number = 10; // Initially assigns the value 10 4 | console.log("Initial value:", number); // Logs the initial value 5 | number = 20; // Updates the value to 20 6 | console.log("Updated value:", number); // Logs the updated value 7 | } 8 | updateVariable(); 9 | // We assign a value to a variable and then update it, showing how values can change. 10 | -------------------------------------------------------------------------------- /day-10/q28/main.js: -------------------------------------------------------------------------------- 1 | var age = 25; 2 | if (age < 2) { 3 | console.log("The person is a baby."); 4 | } 5 | else if (age < 4) { 6 | console.log("The person is a toddler."); 7 | } 8 | else if (age < 13) { 9 | console.log("The person is a kid."); 10 | } 11 | else if (age < 20) { 12 | console.log("The person is a teenager."); 13 | } 14 | else if (age < 65) { 15 | console.log("The person is an adult."); 16 | } 17 | else { 18 | console.log("The person is an elder."); 19 | } 20 | -------------------------------------------------------------------------------- /day-42/q125/main.ts: -------------------------------------------------------------------------------- 1 | // An object with multiple properties and a method that interacts with them using 'this' 2 | const rectangle = { 3 | length: 4, 4 | width: 5, 5 | calculateArea: function () { 6 | return this.length * this.width; // 'this' accesses 'length' and 'width' properties of the object 7 | }, 8 | }; 9 | 10 | console.log(rectangle.calculateArea()); // Outputs: 20 11 | // The 'calculateArea' method uses 'this' to compute the area based on the object's own dimensions. 12 | -------------------------------------------------------------------------------- /day-18/q54/main.ts: -------------------------------------------------------------------------------- 1 | // A way to make a flexible list 2 | function createObjectWithDynamicKey(key: string, value: string) { 3 | let dynamicObject = {}; 4 | // Setting up a section in the list with a changeable name 5 | dynamicObject[key] = value; 6 | return dynamicObject; 7 | } 8 | 9 | // Using the flexible list setup for a user's preference 10 | let userPreference = createObjectWithDynamicKey("theme", "dark"); 11 | 12 | // Showing the user's choice 13 | console.log(userPreference); 14 | -------------------------------------------------------------------------------- /day-21/q63/main.js: -------------------------------------------------------------------------------- 1 | // Describing a circle using our Shape type 2 | var circle = { 3 | kind: "circle", 4 | radius: 5, 5 | }; 6 | // Describing a rectangle using our Shape type 7 | var rectangle = { 8 | kind: "rectangle", 9 | width: 10, 10 | height: 20, 11 | }; 12 | // Showing what we described 13 | console.log(circle); // Here's the circle 14 | console.log(rectangle); // And here's the rectangle 15 | // We made a flexible program that can describe different shapes in detail. 16 | -------------------------------------------------------------------------------- /day-27/q80/main.js: -------------------------------------------------------------------------------- 1 | // Starting with our car object 2 | var car = { 3 | make: "Toyota", 4 | model: "Corolla", 5 | year: 2020, 6 | }; 7 | // Adding a new property 'color' and updating 'year' 8 | car.color = "blue"; // Adds a new property 'color' 9 | car.year = 2021; // Updates the 'year' property 10 | // Showing the updated car object 11 | console.log(car); // Outputs the car object with the new color and updated year 12 | // Now our car is blue and its model year is updated to 2021. 13 | -------------------------------------------------------------------------------- /day-35/q104/main.js: -------------------------------------------------------------------------------- 1 | // This function generates a random hexadecimal color code 2 | function getRandomHexColor() { 3 | var color = "#" + 4 | Math.floor(Math.random() * 0xffffff) 5 | .toString(16) 6 | .padStart(6, "0"); 7 | return color; // Returns the random color code 8 | } 9 | console.log(getRandomHexColor()); // Outputs a random hex color code like #ff3e12 10 | // We generate a random number, convert it to hexadecimal, and ensure it's 6 characters long. 11 | -------------------------------------------------------------------------------- /day-42/q125/main.js: -------------------------------------------------------------------------------- 1 | // An object with multiple properties and a method that interacts with them using 'this' 2 | var rectangle = { 3 | length: 4, 4 | width: 5, 5 | calculateArea: function () { 6 | return this.length * this.width; // 'this' accesses 'length' and 'width' properties of the object 7 | }, 8 | }; 9 | console.log(rectangle.calculateArea()); // Outputs: 20 10 | // The 'calculateArea' method uses 'this' to compute the area based on the object's own dimensions. 11 | -------------------------------------------------------------------------------- /day-44/q131/Person.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.Person = void 0; 4 | // In file: Person.ts 5 | var Person = /** @class */ (function () { 6 | function Person(name) { 7 | this.name = name; 8 | } 9 | Person.prototype.greet = function () { 10 | console.log("Hello, my name is ".concat(this.name)); 11 | }; 12 | return Person; 13 | }()); 14 | exports.Person = Person; 15 | // Exports the Person class 16 | -------------------------------------------------------------------------------- /day-66/TS-Type-System-Concepts/05-Intersection-Type.ts: -------------------------------------------------------------------------------- 1 | /********************* 2 | * INTERSECTION TYPE * 3 | *********************/ 4 | 5 | type FirstType = { 6 | name: string; 7 | age: number; 8 | }; 9 | 10 | type SecondType = { 11 | address: string; 12 | phone: string; 13 | }; 14 | 15 | type CombinedType = FirstType & SecondType; 16 | 17 | const person: CombinedType = { 18 | name: "John Doe", 19 | age: 30, 20 | address: "123 Main St", 21 | phone: "123-456-7890", 22 | }; 23 | -------------------------------------------------------------------------------- /day-27/q80/main.ts: -------------------------------------------------------------------------------- 1 | // Starting with our car object 2 | let car = { 3 | make: "Toyota", 4 | model: "Corolla", 5 | year: 2020, 6 | }; 7 | 8 | // Adding a new property 'color' and updating 'year' 9 | car.color = "blue"; // Adds a new property 'color' 10 | car.year = 2021; // Updates the 'year' property 11 | 12 | // Showing the updated car object 13 | console.log(car); // Outputs the car object with the new color and updated year 14 | // Now our car is blue and its model year is updated to 2021. 15 | -------------------------------------------------------------------------------- /day-30/README.md: -------------------------------------------------------------------------------- 1 | # Day-30 of `100-Days-Of-Code` Challenge 2 | 3 | **Question 88:** Converting Strings to Numbers: Write a function that takes a string representation of a number (e.g., "123") and converts it into an actual number type. 4 | 5 | **Question 89:** Rounding Numbers: Create a function that takes a number with decimals (e.g., `3.14159`) and rounds it to two decimal places. 6 | 7 | **Question 90:** Generating Random Numbers: Write a function that generates a random number between 1 and 10, inclusive. -------------------------------------------------------------------------------- /day-31/q92/main.js: -------------------------------------------------------------------------------- 1 | // This function removes the last element from an array and returns it 2 | function removeLastElement(arr) { 3 | return arr.pop(); // Removes and returns the last element of the array 4 | } 5 | // Example: Removing the last fruit from the array 6 | var fruits = ["Apple", "Banana", "Cherry"]; 7 | console.log(removeLastElement(fruits)); // Outputs: 'Cherry' 8 | console.log(fruits); // Outputs: ['Apple', 'Banana'] 9 | // Here, we take out the last fruit and show the updated list. 10 | -------------------------------------------------------------------------------- /day-35/q104/main.ts: -------------------------------------------------------------------------------- 1 | // This function generates a random hexadecimal color code 2 | function getRandomHexColor(): string { 3 | const color = 4 | "#" + 5 | Math.floor(Math.random() * 0xffffff) 6 | .toString(16) 7 | .padStart(6, "0"); 8 | return color; // Returns the random color code 9 | } 10 | 11 | console.log(getRandomHexColor()); // Outputs a random hex color code like #ff3e12 12 | // We generate a random number, convert it to hexadecimal, and ensure it's 6 characters long. 13 | -------------------------------------------------------------------------------- /day-36/q108/main.js: -------------------------------------------------------------------------------- 1 | // This function compares two strings, ignoring case sensitivity 2 | function areStringsEqualIgnoreCase(str1, str2) { 3 | // Converts both strings to lowercase before comparison 4 | return str1.toLowerCase() === str2.toLowerCase(); 5 | } 6 | console.log(areStringsEqualIgnoreCase("hello", "Hello")); // Outputs: true 7 | console.log(areStringsEqualIgnoreCase("world", "Word")); // Outputs: false 8 | // We make both strings lowercase to ensure the comparison ignores case differences. 9 | -------------------------------------------------------------------------------- /day-11/q32/main.js: -------------------------------------------------------------------------------- 1 | var current_users = ["user1", "admin", "user3", "user4", "user5"]; 2 | var new_users = ["User1", "User6", "user7", "admin", "User9"]; 3 | new_users.forEach(function (newUser) { 4 | if (current_users.some(function (currentUser) { return currentUser.toLowerCase() === newUser.toLowerCase(); })) { 5 | console.log("".concat(newUser, " will need to enter a new username.")); 6 | } 7 | else { 8 | console.log("".concat(newUser, " is available.")); 9 | } 10 | }); 11 | -------------------------------------------------------------------------------- /day-11/q32/main.ts: -------------------------------------------------------------------------------- 1 | let current_users: string[] = ["user1", "admin", "user3", "user4", "user5"]; 2 | let new_users: string[] = ["User1", "User6", "user7", "admin", "User9"]; 3 | 4 | new_users.forEach((newUser) => { 5 | if ( 6 | current_users.some( 7 | (currentUser) => currentUser.toLowerCase() === newUser.toLowerCase() 8 | ) 9 | ) { 10 | console.log(`${newUser} will need to enter a new username.`); 11 | } else { 12 | console.log(`${newUser} is available.`); 13 | } 14 | }); 15 | -------------------------------------------------------------------------------- /day-20/q59/main.js: -------------------------------------------------------------------------------- 1 | // This program makes a function that adds a specific number 2 | function makeAdder(valueToAdd) { 3 | // This is the magic box. It takes a number and adds your special number to it 4 | return function (number) { 5 | return number + valueToAdd; 6 | }; 7 | } 8 | // Making a magic box that adds 5 9 | var addFive = makeAdder(5); 10 | console.log(addFive(10)); // If we put 10 in the box, it gives us 15 11 | // We made a function (magic box) that adds 5 to any number. 12 | -------------------------------------------------------------------------------- /day-48/q144/main.js: -------------------------------------------------------------------------------- 1 | // Example using Promise.all to wait for multiple promises to resolve 2 | var promise1 = Promise.resolve(3); 3 | var promise2 = 42; 4 | var promise3 = new Promise(function (resolve) { 5 | setTimeout(resolve, 100, "foo"); 6 | }); 7 | Promise.all([promise1, promise2, promise3]).then(function (values) { 8 | console.log(values); // Outputs: [3, 42, "foo"] 9 | }); 10 | // This demonstrates how Promise.all waits for all promises to resolve and then logs the array of their results. 11 | -------------------------------------------------------------------------------- /day-14/q42/main.ts: -------------------------------------------------------------------------------- 1 | let magicians: string[] = ["Alice", "David", "Chris"]; 2 | 3 | function show_magicians(magicians: string[]) { 4 | magicians.forEach((magician) => { 5 | console.log(magician); 6 | }); 7 | } 8 | 9 | function make_great(magicians: string[]) { 10 | for (let i = 0; i < magicians.length; i++) { 11 | magicians[i] = magicians[i] + " the Great"; 12 | } 13 | } 14 | 15 | make_great(magicians); // Modifies the original array 16 | show_magicians(magicians); // Shows modified names 17 | -------------------------------------------------------------------------------- /day-20/q58/main.ts: -------------------------------------------------------------------------------- 1 | // This program calculates the average of all scores given 2 | function averageScore(...scores: number[]): number { 3 | // Adds all scores together and divides by the number of scores 4 | let total = scores.reduce((sum, score) => sum + score, 0); 5 | return total / scores.length; 6 | } 7 | 8 | // Example: finding the average of four scores 9 | console.log(averageScore(80, 90, 100, 70)); // Shows the average score 10 | // We add up all the scores, then divide by how many there are. 11 | -------------------------------------------------------------------------------- /day-47/q139/main.js: -------------------------------------------------------------------------------- 1 | // Reserved word: let - used to declare a block-scoped local variable 2 | var count = 5; 3 | // Reserved word: if - used to execute a block of code if a specified condition is true 4 | if (count > 0) { 5 | console.log("Count is greater than 0."); 6 | } 7 | // Reserved word: return - used to exit a function and return a value from that function 8 | function add(a, b) { 9 | return a + b; 10 | } 11 | // Demonstrates valid use cases for the reserved words 'let', 'if', and 'return'. 12 | -------------------------------------------------------------------------------- /day-48/q144/main.ts: -------------------------------------------------------------------------------- 1 | // Example using Promise.all to wait for multiple promises to resolve 2 | const promise1 = Promise.resolve(3); 3 | const promise2 = 42; 4 | const promise3 = new Promise((resolve) => { 5 | setTimeout(resolve, 100, "foo"); 6 | }); 7 | 8 | Promise.all([promise1, promise2, promise3]).then((values) => { 9 | console.log(values); // Outputs: [3, 42, "foo"] 10 | }); 11 | // This demonstrates how Promise.all waits for all promises to resolve and then logs the array of their results. 12 | -------------------------------------------------------------------------------- /day-18/q53/main.ts: -------------------------------------------------------------------------------- 1 | // A list showing a programmer's skills in detail 2 | let developerSkills = { 3 | languages: ["JavaScript", "TypeScript", "Python"], 4 | frameworks: ["React", "Angular", "Vue"], 5 | tools: ["Git", "Webpack", "Docker"], 6 | }; 7 | 8 | // Getting specific skills from the list 9 | let { languages, frameworks, tools } = developerSkills; 10 | 11 | // Showing a skill from each category 12 | console.log( 13 | `Language: ${languages[0]}, Framework: ${frameworks[0]}, Tool: ${tools[0]}` 14 | ); 15 | -------------------------------------------------------------------------------- /day-40/q120/main.js: -------------------------------------------------------------------------------- 1 | // Defines an array of favorite movies 2 | var favoriteMovies = [ 3 | "Inception", 4 | "The Matrix", 5 | "Interstellar", 6 | "The Prestige", 7 | ]; 8 | // Uses a for...of loop to iterate through favoriteMovies 9 | for (var _i = 0, favoriteMovies_1 = favoriteMovies; _i < favoriteMovies_1.length; _i++) { 10 | var movie = favoriteMovies_1[_i]; 11 | console.log(movie); // Logs each movie name 12 | } 13 | // Each movie in the array is logged to the console, one at a time. 14 | -------------------------------------------------------------------------------- /day-53/README.md: -------------------------------------------------------------------------------- 1 | # Day-53 of `100-Days-Of-Code` Challenge 2 | 3 | **Day-53 Task:** 4 | Watch the following video to learn about Chrome DevTools: 5 | [Fun & powerful: Intro to Chrome DevTools](https://www.youtube.com/watch?v=t1c5tNPpXjs&t=23s) 6 | 7 | Chrome DevTools is a set of web developer tools built directly into the Google Chrome browser. DevTools can help you edit pages on-the-fly and diagnose problems quickly, which ultimately helps you build better websites, faster, watch the video to learn more about Chrome DevTools. -------------------------------------------------------------------------------- /day-37/q111/main.ts: -------------------------------------------------------------------------------- 1 | // This function categorizes a person's age group 2 | function categorizeAge(age: number): string { 3 | if (age < 13) { 4 | return "child"; 5 | } else if (age <= 19) { 6 | return "teenager"; 7 | } else { 8 | return "adult"; 9 | } 10 | } 11 | 12 | console.log(categorizeAge(12)); // Outputs: child 13 | console.log(categorizeAge(18)); // Outputs: teenager 14 | console.log(categorizeAge(25)); // Outputs: adult 15 | // Based on the age provided, we log the corresponding age group. 16 | -------------------------------------------------------------------------------- /day-47/q139/main.ts: -------------------------------------------------------------------------------- 1 | // Reserved word: let - used to declare a block-scoped local variable 2 | let count = 5; 3 | 4 | // Reserved word: if - used to execute a block of code if a specified condition is true 5 | if (count > 0) { 6 | console.log("Count is greater than 0."); 7 | } 8 | 9 | // Reserved word: return - used to exit a function and return a value from that function 10 | function add(a, b) { 11 | return a + b; 12 | } 13 | 14 | // Demonstrates valid use cases for the reserved words 'let', 'if', and 'return'. 15 | -------------------------------------------------------------------------------- /day-21/q62/main.ts: -------------------------------------------------------------------------------- 1 | // Creating a blueprint (interface) for student information 2 | interface Student { 3 | name: string; 4 | age: number; 5 | courses: string[]; 6 | } 7 | 8 | // Filling in the blueprint with an example student 9 | let student: Student = { 10 | name: "Alice", 11 | age: 22, 12 | courses: ["Math", "Science", "History"], 13 | }; 14 | 15 | // Showing the student's information 16 | console.log(student); 17 | // We're using the blueprint to make sure our student has a name, age, and list of courses. 18 | -------------------------------------------------------------------------------- /day-49/q145/main.js: -------------------------------------------------------------------------------- 1 | // This function accepts a callback function and invokes it with given arguments 2 | function executeCallback(callback, arg1, arg2) { 3 | callback(arg1, arg2); // Invokes the callback with the specified arguments 4 | } 5 | // Example callback function that adds two numbers 6 | var add = function (a, b) { 7 | console.log(a + b); // Outputs the sum of a and b 8 | }; 9 | executeCallback(add, 5, 3); // Outputs: 8 10 | // Demonstrates invoking a callback function with arguments to perform an addition. 11 | -------------------------------------------------------------------------------- /day-65/TS-Function/03-Function-Rest-Parameter.ts: -------------------------------------------------------------------------------- 1 | /*************************** 2 | * FUNCTION REST PARAMETER * 3 | ***************************/ 4 | 5 | // Function with a rest parameter and type annotations 6 | function addAll(...nums: number[]): number { 7 | let result = 0; 8 | for (let i = 0; i < nums.length; i++) { 9 | result += nums[i]; 10 | } 11 | return result; 12 | } 13 | 14 | // Calling the function with various numeric arguments 15 | console.log(addAll(10, 20, 30, 100, 10.5, +true)); // Output: 170.5 16 | -------------------------------------------------------------------------------- /day-26/q77/main.ts: -------------------------------------------------------------------------------- 1 | // This function greets a user by name, or greets an anonymous user if no name is provided 2 | function greetUser(name: string = "anonymous") { 3 | // Says hello to the given name or to an anonymous user 4 | console.log(`Hello, ${name}!`); 5 | } 6 | 7 | // Trying the function with a name and without 8 | greetUser("Alice"); // Outputs: Hello, Alice! 9 | greetUser(); // Outputs: Hello, anonymous! 10 | // We see how our function can say hello to someone by name, or just say hello if we don't know the name. 11 | -------------------------------------------------------------------------------- /day-28/README.md: -------------------------------------------------------------------------------- 1 | # Day-28 of `100-Days-Of-Code` Challenge 2 | 3 | **Question 82:** Find the Length of a String: Write a function that takes a string as an argument and returns the number of characters in the string. 4 | 5 | **Question 83:** Converting to Upper and Lower Case: Create a function that takes a string, converts it to uppercase, then to lowercase, and logs both. 6 | 7 | **Question 84:** Replacing Text in a String: Write a function that takes a sentence and replaces all instances of the word "JavaScript" with "TypeScript". 8 | -------------------------------------------------------------------------------- /day-29/README.md: -------------------------------------------------------------------------------- 1 | # Day-29 of `100-Days-Of-Code` Challenge 2 | 3 | **Question 85:** Finding the Position of a Substring: Write a function that locates the first occurrence of the word "code" within any given string and returns its position. 4 | 5 | **Question 86:** Checking for Text Presence: Create a function that checks if the word "JavaScript" is present in a given string. It should return `true` if found, otherwise `false`. 6 | 7 | **Question 87:** Extracting a Substring: Demonstrate how to extract the first 10 characters from a string. 8 | -------------------------------------------------------------------------------- /day-36/q108/main.ts: -------------------------------------------------------------------------------- 1 | // This function compares two strings, ignoring case sensitivity 2 | function areStringsEqualIgnoreCase(str1: string, str2: string): boolean { 3 | // Converts both strings to lowercase before comparison 4 | return str1.toLowerCase() === str2.toLowerCase(); 5 | } 6 | 7 | console.log(areStringsEqualIgnoreCase("hello", "Hello")); // Outputs: true 8 | console.log(areStringsEqualIgnoreCase("world", "Word")); // Outputs: false 9 | // We make both strings lowercase to ensure the comparison ignores case differences. 10 | -------------------------------------------------------------------------------- /day-37/q111/main.js: -------------------------------------------------------------------------------- 1 | // This function categorizes a person's age group 2 | function categorizeAge(age) { 3 | if (age < 13) { 4 | return "child"; 5 | } 6 | else if (age <= 19) { 7 | return "teenager"; 8 | } 9 | else { 10 | return "adult"; 11 | } 12 | } 13 | console.log(categorizeAge(12)); // Outputs: child 14 | console.log(categorizeAge(18)); // Outputs: teenager 15 | console.log(categorizeAge(25)); // Outputs: adult 16 | // Based on the age provided, we log the corresponding age group. 17 | -------------------------------------------------------------------------------- /day-43/q128/main.js: -------------------------------------------------------------------------------- 1 | // Arrow function that calculates the product of all its parameters 2 | var multiplyParameters = function () { 3 | var numbers = []; 4 | for (var _i = 0; _i < arguments.length; _i++) { 5 | numbers[_i] = arguments[_i]; 6 | } 7 | return numbers.reduce(function (total, number) { return total * number; }, 1); 8 | }; 9 | console.log(multiplyParameters(2, 3, 4)); // Outputs: 24 10 | // This function uses the rest parameter syntax to take any number of arguments, then multiplies them together. 11 | -------------------------------------------------------------------------------- /day-31/q92/main.ts: -------------------------------------------------------------------------------- 1 | // This function removes the last element from an array and returns it 2 | function removeLastElement(arr: T[]): T | undefined { 3 | return arr.pop(); // Removes and returns the last element of the array 4 | } 5 | 6 | // Example: Removing the last fruit from the array 7 | const fruits: string[] = ["Apple", "Banana", "Cherry"]; 8 | console.log(removeLastElement(fruits)); // Outputs: 'Cherry' 9 | console.log(fruits); // Outputs: ['Apple', 'Banana'] 10 | // Here, we take out the last fruit and show the updated list. 11 | -------------------------------------------------------------------------------- /day-20/q59/main.ts: -------------------------------------------------------------------------------- 1 | // This program makes a function that adds a specific number 2 | function makeAdder(valueToAdd: number): (number) => number { 3 | // This is the magic box. It takes a number and adds your special number to it 4 | return function (number: number): number { 5 | return number + valueToAdd; 6 | }; 7 | } 8 | 9 | // Making a magic box that adds 5 10 | let addFive = makeAdder(5); 11 | console.log(addFive(10)); // If we put 10 in the box, it gives us 15 12 | // We made a function (magic box) that adds 5 to any number. 13 | -------------------------------------------------------------------------------- /day-28/q83/main.js: -------------------------------------------------------------------------------- 1 | // This function changes a string to uppercase and then to lowercase 2 | function convertCase(str) { 3 | var upperStr = str.toUpperCase(); // Converts to uppercase 4 | var lowerStr = str.toLowerCase(); // Converts to lowercase 5 | console.log("Uppercase:", upperStr, "Lowercase:", lowerStr); 6 | } 7 | // Example: Changing the case of "Hello World" 8 | convertCase("Hello World"); // Outputs: "Uppercase: HELLO WORLD Lowercase: hello world" 9 | // We're showing the same text in all uppercase and then all lowercase. 10 | -------------------------------------------------------------------------------- /day-24/q71/main.ts: -------------------------------------------------------------------------------- 1 | // Using `let` for a variable that can be reassigned 2 | let age = 25; 3 | age = 26; // Works fine because `let` allows reassignment 4 | console.log(age); // Shows 26 5 | 6 | // Trying to reassign a `const`-declared variable 7 | const name = "Alice"; 8 | try { 9 | name = "Bob"; // This line will cause an error 10 | } catch (error) { 11 | console.log("Error: Can't reassign a `const`-declared variable."); // This message is shown 12 | } 13 | // This example illustrates that `const` prevents changing the variable once it's set. 14 | -------------------------------------------------------------------------------- /day-17/q49/main.js: -------------------------------------------------------------------------------- 1 | // Defines a function that accepts multiple hobbies as arguments 2 | function logHobbies() { 3 | var hobbies = []; 4 | for (var _i = 0; _i < arguments.length; _i++) { 5 | hobbies[_i] = arguments[_i]; 6 | } 7 | // Loops through each hobby in the array 8 | hobbies.forEach(function (hobby) { 9 | // Logs a statement for each hobby 10 | console.log("I enjoy ".concat(hobby, ".")); 11 | }); 12 | } 13 | // Calls the function with three hobbies 14 | logHobbies("reading", "coding", "cycling"); 15 | -------------------------------------------------------------------------------- /day-21/q61/main.js: -------------------------------------------------------------------------------- 1 | // Making a list (enum) for different types of vehicles 2 | var VehicleType; 3 | (function (VehicleType) { 4 | VehicleType[VehicleType["Car"] = 0] = "Car"; 5 | VehicleType[VehicleType["Truck"] = 1] = "Truck"; 6 | VehicleType[VehicleType["Motorcycle"] = 2] = "Motorcycle"; 7 | })(VehicleType || (VehicleType = {})); 8 | // Showing one type of vehicle from the list 9 | console.log(VehicleType.Car); // It shows 0 because enums start counting from 0 10 | // Here, we're just checking what number the Car category got in our list. 11 | -------------------------------------------------------------------------------- /day-24/q71/main.js: -------------------------------------------------------------------------------- 1 | // Using `let` for a variable that can be reassigned 2 | var age = 25; 3 | age = 26; // Works fine because `let` allows reassignment 4 | console.log(age); // Shows 26 5 | // Trying to reassign a `const`-declared variable 6 | var name = "Alice"; 7 | try { 8 | name = "Bob"; // This line will cause an error 9 | } 10 | catch (error) { 11 | console.log("Error: Can't reassign a `const`-declared variable."); // This message is shown 12 | } 13 | // This example illustrates that `const` prevents changing the variable once it's set. 14 | -------------------------------------------------------------------------------- /day-26/q78/main.js: -------------------------------------------------------------------------------- 1 | // Function declaration for squaring a number 2 | function squareDeclaration(number) { 3 | return number * number; 4 | } 5 | // Function expression for squaring a number 6 | var squareExpression = function (number) { 7 | return number * number; 8 | }; 9 | // Using both functions to square the number 4 10 | console.log(squareDeclaration(4)); // Outputs: 16 11 | console.log(squareExpression(4)); // Outputs: 16 12 | // Both methods give us the same result, showing two different ways to create functions that do the same thing. 13 | -------------------------------------------------------------------------------- /day-28/q83/main.ts: -------------------------------------------------------------------------------- 1 | // This function changes a string to uppercase and then to lowercase 2 | function convertCase(str: string) { 3 | let upperStr = str.toUpperCase(); // Converts to uppercase 4 | let lowerStr = str.toLowerCase(); // Converts to lowercase 5 | 6 | console.log("Uppercase:", upperStr, "Lowercase:", lowerStr); 7 | } 8 | 9 | // Example: Changing the case of "Hello World" 10 | convertCase("Hello World"); // Outputs: "Uppercase: HELLO WORLD Lowercase: hello world" 11 | // We're showing the same text in all uppercase and then all lowercase. 12 | -------------------------------------------------------------------------------- /day-33/q98/main.js: -------------------------------------------------------------------------------- 1 | // Calculates how many days are left until New Year's Day 2 | function daysUntilNewYear() { 3 | var today = new Date(); 4 | var newYear = new Date(today.getFullYear() + 1, 0, 1); // January 1st of next year 5 | var diff = newYear.getTime() - today.getTime(); // Difference in milliseconds 6 | var days = Math.ceil(diff / (1000 * 60 * 60 * 24)); // Converts to days 7 | return days; 8 | } 9 | console.log(daysUntilNewYear() + " days until New Year."); 10 | // Tells us how many days there are until the next New Year's Day. 11 | -------------------------------------------------------------------------------- /day-45/q135/main.js: -------------------------------------------------------------------------------- 1 | // Reusing the person object from Question 133 2 | var person = { 3 | name: "Alice", 4 | age: 30, 5 | city: "Wonderland", 6 | }; 7 | // Converts the object into a JSON string with indentation 8 | var jsonString = JSON.stringify(person, null, 2); // The '2' specifies the number of spaces to use as white space 9 | console.log(jsonString); 10 | /* Outputs: 11 | { 12 | "name": "Alice", 13 | "age": 30, 14 | "city": "Wonderland" 15 | } 16 | */ 17 | // Shows how adding indentation to the JSON string makes it easier to read. 18 | -------------------------------------------------------------------------------- /day-17/README.md: -------------------------------------------------------------------------------- 1 | # Day-17 of `100-Days-Of-Code` Challenge 2 | 3 | **Q49** - Function with Rest Parameters: Write a function that takes a rest parameter representing multiple hobbies. It should log each hobby with a statement saying you enjoy that hobby. 4 | 5 | **Q50** - Multiline Template Literals: Use template literals to create a multiline string that describes your ideal day. Include at least three different activities. 6 | 7 | **Q51** - Refactoring to Arrow Functions: Take a simple function that calculates the area of a rectangle and refactor it into an arrow function. -------------------------------------------------------------------------------- /day-23/README.md: -------------------------------------------------------------------------------- 1 | # Day-23 of `100-Days-Of-Code` Challenge 2 | 3 | **Q67** - Arithmetic with Mixed Types: Write a function that takes two parameters: a number and a string that represents a number (e.g., "5"). Return their sum as a number. 4 | 5 | **Q68** - Multiplying Decimals: Create a function that accepts two decimal numbers and returns their product. Round the result to two decimal places. 6 | 7 | **Q69** - Dividing and Finding the Remainder: Write a function that divides two numbers and returns both the quotient and the remainder. Use an object to return both values. -------------------------------------------------------------------------------- /day-27/q81/main.ts: -------------------------------------------------------------------------------- 1 | // This function shows every detail about an object 2 | function logObjectProperties(obj: object) { 3 | for (let property in obj) { 4 | // Loops through each property in the object 5 | console.log(`${property}: ${obj[property]}`); 6 | // Shows the property name and its value 7 | } 8 | } 9 | 10 | // Using the function with a car object 11 | logObjectProperties({ 12 | make: "Toyota", 13 | model: "Corolla", 14 | year: 2021, 15 | color: "blue", 16 | }); 17 | // It tells us each piece of information stored about the car. 18 | -------------------------------------------------------------------------------- /day-21/README.md: -------------------------------------------------------------------------------- 1 | # Day-21 of `100-Days-Of-Code` Challenge 2 | 3 | **Q61** - Making Enums for Vehicles: Let's create categories for vehicles like cars, trucks, and motorcycles using enums, and show one example. 4 | 5 | **Q62** - Making a Student Template: Create a blueprint for student information, including their name, age, and the classes they're taking, and then fill in this blueprint with an example student. 6 | 7 | **Q63** - Shape Shifter: Write a program that can describe either a circle or a rectangle using a special type alias, including properties unique to each shape. -------------------------------------------------------------------------------- /day-25/q74/main.js: -------------------------------------------------------------------------------- 1 | // This function swaps the values of two variables 2 | function swapValues() { 3 | var a = 5, b = 10; // Initially, a is 5 and b is 10 4 | console.log("Before swap: a =", a, "b =", b); 5 | var temp = a; // Temporarily stores the value of a 6 | a = b; // Sets a to b's value 7 | b = temp; // Sets b to a's original value stored in temp 8 | console.log("After swap: a =", a, "b =", b); // Logs the swapped values 9 | } 10 | swapValues(); 11 | // We use a temporary variable to hold one value while we swap them, like a magic trick! 12 | -------------------------------------------------------------------------------- /day-26/q77/main.js: -------------------------------------------------------------------------------- 1 | // This function greets a user by name, or greets an anonymous user if no name is provided 2 | function greetUser(name) { 3 | if (name === void 0) { name = "anonymous"; } 4 | // Says hello to the given name or to an anonymous user 5 | console.log("Hello, ".concat(name, "!")); 6 | } 7 | // Trying the function with a name and without 8 | greetUser("Alice"); // Outputs: Hello, Alice! 9 | greetUser(); // Outputs: Hello, anonymous! 10 | // We see how our function can say hello to someone by name, or just say hello if we don't know the name. 11 | -------------------------------------------------------------------------------- /day-33/q98/main.ts: -------------------------------------------------------------------------------- 1 | // Calculates how many days are left until New Year's Day 2 | function daysUntilNewYear(): number { 3 | const today = new Date(); 4 | const newYear = new Date(today.getFullYear() + 1, 0, 1); // January 1st of next year 5 | const diff = newYear.getTime() - today.getTime(); // Difference in milliseconds 6 | const days = Math.ceil(diff / (1000 * 60 * 60 * 24)); // Converts to days 7 | return days; 8 | } 9 | 10 | console.log(daysUntilNewYear() + " days until New Year."); 11 | // Tells us how many days there are until the next New Year's Day. 12 | -------------------------------------------------------------------------------- /day-45/q135/main.ts: -------------------------------------------------------------------------------- 1 | // Reusing the person object from Question 133 2 | const person = { 3 | name: "Alice", 4 | age: 30, 5 | city: "Wonderland", 6 | }; 7 | 8 | // Converts the object into a JSON string with indentation 9 | const jsonString = JSON.stringify(person, null, 2); // The '2' specifies the number of spaces to use as white space 10 | 11 | console.log(jsonString); 12 | /* Outputs: 13 | { 14 | "name": "Alice", 15 | "age": 30, 16 | "city": "Wonderland" 17 | } 18 | */ 19 | // Shows how adding indentation to the JSON string makes it easier to read. 20 | -------------------------------------------------------------------------------- /day-46/q138/main.js: -------------------------------------------------------------------------------- 1 | // Sample code snippet for setting a breakpoint 2 | console.log("Before breakpoint"); 3 | // Set a breakpoint on the following line using your browser's developer tools 4 | console.log("This line has a breakpoint set on it in the browser's developer tools"); 5 | console.log("After breakpoint"); 6 | // To use breakpoints, open this code in your browser, open the developer tools, navigate to the Source tab, find this script, and click on the line number where you want to pause execution. When you reload or run your page, execution will pause at the breakpoint. 7 | -------------------------------------------------------------------------------- /day-33/q97/main.ts: -------------------------------------------------------------------------------- 1 | // This function formats the current date as DD-MM-YYYY 2 | function getCurrentDateFormatted(): string { 3 | const now = new Date(); 4 | const day = String(now.getDate()).padStart(2, "0"); // Ensures the day is two digits 5 | const month = String(now.getMonth() + 1).padStart(2, "0"); // Adds 1 because months are 0-indexed 6 | const year = now.getFullYear(); 7 | return `${day}-${month}-${year}`; 8 | } 9 | 10 | console.log(getCurrentDateFormatted()); // Outputs the current date in DD-MM-YYYY format 11 | // Shows today's date, neatly formatted. 12 | -------------------------------------------------------------------------------- /day-65/TS-Function/06-void-&-never.ts: -------------------------------------------------------------------------------- 1 | /**************** 2 | * VOID & NEVER * 3 | ****************/ 4 | 5 | // void 6 | function greet(name: string): void { 7 | console.log(`Hello, ${name}!`); 8 | } 9 | 10 | function noReturnValue(): void { 11 | // This function doesn't return a value (implicitly returns undefined). 12 | } 13 | 14 | // never 15 | function throwError(message: string): never { 16 | throw new Error(message); 17 | } 18 | 19 | function infiniteLoop(): never { 20 | while (true) { 21 | // This function never exits (infinite loop). 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /day-18/q53/main.js: -------------------------------------------------------------------------------- 1 | // A list showing a programmer's skills in detail 2 | var developerSkills = { 3 | languages: ["JavaScript", "TypeScript", "Python"], 4 | frameworks: ["React", "Angular", "Vue"], 5 | tools: ["Git", "Webpack", "Docker"], 6 | }; 7 | // Getting specific skills from the list 8 | var languages = developerSkills.languages, frameworks = developerSkills.frameworks, tools = developerSkills.tools; 9 | // Showing a skill from each category 10 | console.log("Language: ".concat(languages[0], ", Framework: ").concat(frameworks[0], ", Tool: ").concat(tools[0])); 11 | -------------------------------------------------------------------------------- /day-20/q60/main.ts: -------------------------------------------------------------------------------- 1 | // This profile sets itself up and can share info about the user 2 | let userProfile = (function () { 3 | // The user's details are kept inside 4 | let name = "John"; 5 | let age = 30; 6 | 7 | // This part shares the user's details 8 | return { 9 | displayInfo: function () { 10 | console.log(`Name: ${name}, Age: ${age}`); 11 | }, 12 | }; 13 | })(); 14 | 15 | // Asking the profile to tell us about the user 16 | userProfile.displayInfo(); // It says the user's name and age 17 | // We made a self-setup profile that can talk about the user. 18 | -------------------------------------------------------------------------------- /day-23/q69/main.js: -------------------------------------------------------------------------------- 1 | // This function divides two numbers and finds the quotient and remainder 2 | function divideAndRemainder(dividend, divisor) { 3 | // Calculates the quotient and remainder 4 | var quotient = Math.floor(dividend / divisor); 5 | var remainder = dividend % divisor; 6 | // Returns both in an object 7 | return { quotient: quotient, remainder: remainder }; 8 | } 9 | // Trying it with 10 divided by 3 10 | console.log(divideAndRemainder(10, 3)); // Shows { quotient: 3, remainder: 1 } 11 | // It shows how many times 3 goes into 10, and what's left over. 12 | -------------------------------------------------------------------------------- /day-25/q74/main.ts: -------------------------------------------------------------------------------- 1 | // This function swaps the values of two variables 2 | function swapValues() { 3 | let a = 5, 4 | b = 10; // Initially, a is 5 and b is 10 5 | console.log("Before swap: a =", a, "b =", b); 6 | 7 | let temp = a; // Temporarily stores the value of a 8 | a = b; // Sets a to b's value 9 | b = temp; // Sets b to a's original value stored in temp 10 | 11 | console.log("After swap: a =", a, "b =", b); // Logs the swapped values 12 | } 13 | 14 | swapValues(); 15 | // We use a temporary variable to hold one value while we swap them, like a magic trick! 16 | -------------------------------------------------------------------------------- /day-28/q84/main.js: -------------------------------------------------------------------------------- 1 | // This function swaps "JavaScript" with "TypeScript" in a sentence 2 | function replaceJavaScriptWithTypeScript(sentence) { 3 | return sentence.replace(/JavaScript/g, "TypeScript"); 4 | // Uses a regular expression with the 'g' flag for a global replacement 5 | } 6 | // Example: Changing a programming language name in a sentence 7 | console.log(replaceJavaScriptWithTypeScript("I love JavaScript and JavaScript is awesome!")); 8 | // Outputs: "I love TypeScript and TypeScript is awesome!" 9 | // Every "JavaScript" in the sentence is changed to "TypeScript". 10 | -------------------------------------------------------------------------------- /day-46/q138/main.ts: -------------------------------------------------------------------------------- 1 | // Sample code snippet for setting a breakpoint 2 | console.log("Before breakpoint"); 3 | // Set a breakpoint on the following line using your browser's developer tools 4 | console.log( 5 | "This line has a breakpoint set on it in the browser's developer tools" 6 | ); 7 | console.log("After breakpoint"); 8 | // To use breakpoints, open this code in your browser, open the developer tools, navigate to the Source tab, find this script, and click on the line number where you want to pause execution. When you reload or run your page, execution will pause at the breakpoint. 9 | -------------------------------------------------------------------------------- /day-50/q150/main.ts: -------------------------------------------------------------------------------- 1 | // Synchronous example 2 | console.log("Before synchronous operation"); 3 | // Simulate a synchronous blocking operation 4 | for (let i = 0; i < 1e9; i++) {} // A long loop 5 | console.log("After synchronous operation"); 6 | 7 | // Asynchronous example 8 | console.log("Before asynchronous operation"); 9 | setTimeout(() => { 10 | console.log("Asynchronous operation completed"); 11 | }, 1000); 12 | console.log("After asynchronous operation setup"); 13 | // Demonstrates how the rest of the code continues to execute without waiting for the asynchronous operation. 14 | -------------------------------------------------------------------------------- /day-09/q26/main.ts: -------------------------------------------------------------------------------- 1 | // Version that passes: 2 | let alien_color = "green"; 3 | 4 | // Q26 Answer: 5 | // Version that runs the if block: 6 | alien_color = "green"; 7 | if (alien_color == "green") { 8 | console.log("You just earned 5 points for shooting the alien"); 9 | } else { 10 | console.log("You just earned 10 points"); 11 | } 12 | 13 | // Version that runs the else block: 14 | alien_color = "yellow"; 15 | if (alien_color == "green") { 16 | console.log("You just earned 5 points for shooting the alien!"); 17 | } else { 18 | console.log("You just earned 10 points!"); 19 | } 20 | -------------------------------------------------------------------------------- /day-15/q45/main.js: -------------------------------------------------------------------------------- 1 | function make_car(manufacturer, model) { 2 | var options = []; 3 | for (var _i = 2; _i < arguments.length; _i++) { 4 | options[_i - 2] = arguments[_i]; 5 | } 6 | var car = { manufacturer: manufacturer, model: model }; 7 | options.forEach(function (_a) { 8 | var key = _a[0], value = _a[1]; 9 | return (car[key] = value); 10 | }); 11 | return car; 12 | } 13 | console.log(make_car("Toyota", "Carolla", ["color", "red"], ["year", 2020])); 14 | console.log(make_car("Ford", "Fiesta", ["color", "blue"], ["sunroof", true])); 15 | -------------------------------------------------------------------------------- /day-27/q81/main.js: -------------------------------------------------------------------------------- 1 | // This function shows every detail about an object 2 | function logObjectProperties(obj) { 3 | for (var property in obj) { 4 | // Loops through each property in the object 5 | console.log("".concat(property, ": ").concat(obj[property])); 6 | // Shows the property name and its value 7 | } 8 | } 9 | // Using the function with a car object 10 | logObjectProperties({ 11 | make: "Toyota", 12 | model: "Corolla", 13 | year: 2021, 14 | color: "blue", 15 | }); 16 | // It tells us each piece of information stored about the car. 17 | -------------------------------------------------------------------------------- /day-33/q97/main.js: -------------------------------------------------------------------------------- 1 | // This function formats the current date as DD-MM-YYYY 2 | function getCurrentDateFormatted() { 3 | var now = new Date(); 4 | var day = String(now.getDate()).padStart(2, "0"); // Ensures the day is two digits 5 | var month = String(now.getMonth() + 1).padStart(2, "0"); // Adds 1 because months are 0-indexed 6 | var year = now.getFullYear(); 7 | return "".concat(day, "-").concat(month, "-").concat(year); 8 | } 9 | console.log(getCurrentDateFormatted()); // Outputs the current date in DD-MM-YYYY format 10 | // Shows today's date, neatly formatted. 11 | -------------------------------------------------------------------------------- /day-50/q150/main.js: -------------------------------------------------------------------------------- 1 | // Synchronous example 2 | console.log("Before synchronous operation"); 3 | // Simulate a synchronous blocking operation 4 | for (var i = 0; i < 1e9; i++) { } // A long loop 5 | console.log("After synchronous operation"); 6 | // Asynchronous example 7 | console.log("Before asynchronous operation"); 8 | setTimeout(function () { 9 | console.log("Asynchronous operation completed"); 10 | }, 1000); 11 | console.log("After asynchronous operation setup"); 12 | // Demonstrates how the rest of the code continues to execute without waiting for the asynchronous operation. 13 | -------------------------------------------------------------------------------- /day-09/q26/main.js: -------------------------------------------------------------------------------- 1 | // Version that passes: 2 | var alien_color = "green"; 3 | // Q26 Answer: 4 | // Version that runs the if block: 5 | alien_color = "green"; 6 | if (alien_color == "green") { 7 | console.log("You just earned 5 points for shooting the alien"); 8 | } 9 | else { 10 | console.log("You just earned 10 points"); 11 | } 12 | // Version that runs the else block: 13 | alien_color = "yellow"; 14 | if (alien_color == "green") { 15 | console.log("You just earned 5 points for shooting the alien!"); 16 | } 17 | else { 18 | console.log("You just earned 10 points!"); 19 | } 20 | -------------------------------------------------------------------------------- /day-26/q78/main.ts: -------------------------------------------------------------------------------- 1 | // Function declaration for squaring a number 2 | function squareDeclaration(number: number): number { 3 | return number * number; 4 | } 5 | 6 | // Function expression for squaring a number 7 | const squareExpression = function (number: number): number { 8 | return number * number; 9 | }; 10 | 11 | // Using both functions to square the number 4 12 | console.log(squareDeclaration(4)); // Outputs: 16 13 | console.log(squareExpression(4)); // Outputs: 16 14 | // Both methods give us the same result, showing two different ways to create functions that do the same thing. 15 | -------------------------------------------------------------------------------- /day-31/q93/main.js: -------------------------------------------------------------------------------- 1 | // This function finds "Banana" in the fruits array and replaces it with "Mango" 2 | function replaceBananaWithMango(fruits) { 3 | var index = fruits.indexOf("Banana"); // Finds the index of "Banana" 4 | if (index !== -1) 5 | fruits[index] = "Mango"; // Replaces "Banana" with "Mango" if found 6 | } 7 | // Example: Replacing "Banana" in the array 8 | var fruits = ["Apple", "Banana", "Cherry"]; 9 | replaceBananaWithMango(fruits); 10 | console.log(fruits); // Outputs: ['Apple', 'Mango', 'Cherry'] 11 | // We're swapping "Banana" for "Mango" in our fruit list. 12 | -------------------------------------------------------------------------------- /day-07/README.md: -------------------------------------------------------------------------------- 1 | # Day-07 of `100-Days-Of-Code` Challenge 2 | 3 | **Q19** - Dinner Guests: Working with one of the programs from Exercises 14 through 18, print a message indicating the number of people you are inviting to dinner. 4 | 5 | **Q20** - Think of something you could store in a array. For example, you could make a list of mountains, rivers, countries, cities, languages, or anything else you’d like. Write a program that creates a list containing these items. 6 | 7 | **Q21** - They think of something you could store in a TypeScript Object. Write a program that creates Objects containing these items. -------------------------------------------------------------------------------- /day-47/q141/main.ts: -------------------------------------------------------------------------------- 1 | // Example use of the 'await' reserved word in asynchronous JavaScript 2 | async function fetchData() { 3 | // Assuming fetchSomething returns a Promise 4 | const data = await fetchSomething(); 5 | console.log(data); 6 | // The 'await' keyword pauses the execution until the Promise settles, and then resumes with the resolved value. 7 | } 8 | 9 | console.log( 10 | "The 'await' keyword allows asynchronous, promise-based behavior to be written in a cleaner, more linear fashion." 11 | ); 12 | // This demonstrates how 'await' improves readability and flow in asynchronous code. 13 | -------------------------------------------------------------------------------- /day-68/TS-Tuple/01-Tuple.ts: -------------------------------------------------------------------------------- 1 | /********* 2 | * TUPLE * 3 | *********/ 4 | 5 | // Defining a tuple type 6 | let article: readonly [number, string, boolean] = [11, "Title One", true]; 7 | 8 | // Assigning a new tuple value to the `article` variable 9 | article = [12, "Title Two", false]; 10 | 11 | // Trying to push a new element into a tuple (will result in an error) 12 | // article.push(100); 13 | 14 | console.log(article); 15 | 16 | // Destructuring the tuple into individual variables 17 | const [id, title, published] = article; 18 | console.log(id); 19 | console.log(title); 20 | console.log(published); -------------------------------------------------------------------------------- /day-27/README.md: -------------------------------------------------------------------------------- 1 | # Day-27 of `100-Days-Of-Code` Challenge 2 | 3 | **Question 79:** Creating and Accessing Object Properties: Construct an object representing a car with properties for make, model, and year. Then, show how you can access the model property of the car. 4 | 5 | **Question 80:** Updating Object Properties: Add a property named `color` to the existing car object, and then update the `year` property to `2021`. Show how to perform these operations. 6 | 7 | **Question 81:** Iterating Over Object Properties: Write a function that takes an object as an argument and logs all of its properties and values. 8 | -------------------------------------------------------------------------------- /day-20/q60/main.js: -------------------------------------------------------------------------------- 1 | // This profile sets itself up and can share info about the user 2 | var userProfile = (function () { 3 | // The user's details are kept inside 4 | var name = "John"; 5 | var age = 30; 6 | // This part shares the user's details 7 | return { 8 | displayInfo: function () { 9 | console.log("Name: ".concat(name, ", Age: ").concat(age)); 10 | }, 11 | }; 12 | })(); 13 | // Asking the profile to tell us about the user 14 | userProfile.displayInfo(); // It says the user's name and age 15 | // We made a self-setup profile that can talk about the user. 16 | -------------------------------------------------------------------------------- /day-31/q93/main.ts: -------------------------------------------------------------------------------- 1 | // This function finds "Banana" in the fruits array and replaces it with "Mango" 2 | function replaceBananaWithMango(fruits: string[]): void { 3 | const index = fruits.indexOf("Banana"); // Finds the index of "Banana" 4 | if (index !== -1) fruits[index] = "Mango"; // Replaces "Banana" with "Mango" if found 5 | } 6 | 7 | // Example: Replacing "Banana" in the array 8 | const fruits: string[] = ["Apple", "Banana", "Cherry"]; 9 | replaceBananaWithMango(fruits); 10 | console.log(fruits); // Outputs: ['Apple', 'Mango', 'Cherry'] 11 | // We're swapping "Banana" for "Mango" in our fruit list. 12 | -------------------------------------------------------------------------------- /day-63/TS-Types/01-Type-Annotations.ts: -------------------------------------------------------------------------------- 1 | /******************** 2 | * TYPE ANNOTATIONS * 3 | ********************/ 4 | 5 | let myNumberExOne: number = 42; 6 | let myStringExOne: string = "Hello, TypeScript"; 7 | 8 | console.log("My Number Is:", myNumberExOne); 9 | console.log("My String Is:", myStringExOne); 10 | 11 | 12 | // Another way to write this code is as follows: 13 | let myNumberExTwo: number; 14 | let myStringExTwo: string; 15 | 16 | myNumberExTwo = 42; 17 | myStringExTwo = "Hello, TypeScript"; 18 | 19 | console.log("My Number Is:", myNumberExTwo); 20 | console.log("My String Is:", myStringExTwo); 21 | -------------------------------------------------------------------------------- /day-66/TS-Type-System-Concepts/03-Nullable-Types.ts: -------------------------------------------------------------------------------- 1 | /****************** 2 | * NULLABLE TYPES * 3 | ******************/ 4 | 5 | let username: string | null = "Glicher"; // The variable can hold a string or null 6 | let ageEx: number | null = null; // The variable can hold a number or null 7 | 8 | function greetUser(username: string | null) { 9 | if (username === null) { 10 | console.log("Hello, Guest!"); 11 | } else { 12 | console.log(`Hello, ${username}!`); 13 | } 14 | } 15 | 16 | greetUser("Glitcher"); // Output: Hello, Glitcher! 17 | greetUser(null); // Output: Hello, Guest! 18 | -------------------------------------------------------------------------------- /day-42/q126/main.ts: -------------------------------------------------------------------------------- 1 | // Demonstrates 'this' behavior change in a nested function 2 | const myObject = { 3 | property: "Value", 4 | outerMethod: function () { 5 | console.log(this.property); // Works as expected, logs "Value" 6 | 7 | const innerMethod = () => { 8 | console.log(this.property); // Still accesses myObject's 'property' due to arrow function capturing 'this' from outer scope 9 | }; 10 | 11 | innerMethod(); 12 | }, 13 | }; 14 | 15 | myObject.outerMethod(); 16 | // This example shows that using an arrow function for the inner method preserves the 'this' context from the outer method. 17 | -------------------------------------------------------------------------------- /day-03/README.md: -------------------------------------------------------------------------------- 1 | # Day-03 of `100-Days-Of-Code` Challenge 2 | 3 | **Q7** - Number Eight: Write addition, subtraction, multiplication, and division operations that each result in the number 8. Be sure to enclose your operations in print statements to see the results. 4 | 5 | **Q8** - You should create four lines that look like this: 6 | console.log(5 + 3) 7 | Your output should simply be four lines with the number 8 appearing once on each line. 8 | 9 | **Q9** - Favorite Number: Store your favorite number in a variable. Then, using that variable, create a message that reveals your favorite number. Print that message. 10 | 11 | 12 | -------------------------------------------------------------------------------- /day-05/q15/main.ts: -------------------------------------------------------------------------------- 1 | // Q14 Answer: 2 | let guests: string[] = ["Albert Einstein", "Marie Curie", "Nikola Tesla"]; 3 | 4 | guests.forEach(guest => { 5 | console.log(`Dear ${guest}, would you like to join me for dinner?`); 6 | }); 7 | 8 | 9 | // Q15 Answer: 10 | let unableToAttend = "Nikola Tesla"; 11 | console.log(`${unableToAttend} can't make it to dinner.`); 12 | 13 | // Replace the guest 14 | let newGuest = "Leonardo da Vinci"; 15 | guests[guests.indexOf(unableToAttend)] = newGuest; 16 | 17 | // New invitations 18 | guests.forEach(guest => { 19 | console.log(`Dear ${guest}, would you like to join me for dinner?`); 20 | }); -------------------------------------------------------------------------------- /day-20/q58/main.js: -------------------------------------------------------------------------------- 1 | // This program calculates the average of all scores given 2 | function averageScore() { 3 | var scores = []; 4 | for (var _i = 0; _i < arguments.length; _i++) { 5 | scores[_i] = arguments[_i]; 6 | } 7 | // Adds all scores together and divides by the number of scores 8 | var total = scores.reduce(function (sum, score) { return sum + score; }, 0); 9 | return total / scores.length; 10 | } 11 | // Example: finding the average of four scores 12 | console.log(averageScore(80, 90, 100, 70)); // Shows the average score 13 | // We add up all the scores, then divide by how many there are. 14 | -------------------------------------------------------------------------------- /day-28/q84/main.ts: -------------------------------------------------------------------------------- 1 | // This function swaps "JavaScript" with "TypeScript" in a sentence 2 | function replaceJavaScriptWithTypeScript(sentence: string): string { 3 | return sentence.replace(/JavaScript/g, "TypeScript"); 4 | // Uses a regular expression with the 'g' flag for a global replacement 5 | } 6 | 7 | // Example: Changing a programming language name in a sentence 8 | console.log( 9 | replaceJavaScriptWithTypeScript( 10 | "I love JavaScript and JavaScript is awesome!" 11 | ) 12 | ); 13 | // Outputs: "I love TypeScript and TypeScript is awesome!" 14 | // Every "JavaScript" in the sentence is changed to "TypeScript". 15 | -------------------------------------------------------------------------------- /day-49/q145/main.ts: -------------------------------------------------------------------------------- 1 | // This function accepts a callback function and invokes it with given arguments 2 | function executeCallback( 3 | callback: (arg1: number, arg2: number) => void, 4 | arg1: number, 5 | arg2: number 6 | ): void { 7 | callback(arg1, arg2); // Invokes the callback with the specified arguments 8 | } 9 | 10 | // Example callback function that adds two numbers 11 | const add = (a: number, b: number) => { 12 | console.log(a + b); // Outputs the sum of a and b 13 | }; 14 | 15 | executeCallback(add, 5, 3); // Outputs: 8 16 | // Demonstrates invoking a callback function with arguments to perform an addition. 17 | -------------------------------------------------------------------------------- /day-65/TS-Function/01-Type-Annotations-With-Function.ts: -------------------------------------------------------------------------------- 1 | /********************************** 2 | * TYPE ANNOTATIONS WITH FUNCTION * 3 | **********************************/ 4 | 5 | // Function to calculate the area of a rectangle 6 | function calculateRectangleArea(lengthRectAngle: number, widthOfRectAngle: number): number { 7 | return lengthRectAngle * widthOfRectAngle; 8 | } 9 | 10 | // Calling the function with valid arguments 11 | const lengthRectAngle = 5; 12 | const widthOfRectAngle = 3; 13 | const area = calculateRectangleArea(lengthRectAngle, widthOfRectAngle); 14 | console.log(`The area of the rectangle is: ${area}`); 15 | -------------------------------------------------------------------------------- /day-23/q69/main.ts: -------------------------------------------------------------------------------- 1 | // This function divides two numbers and finds the quotient and remainder 2 | function divideAndRemainder( 3 | dividend: number, 4 | divisor: number 5 | ): { quotient: number; remainder: number } { 6 | // Calculates the quotient and remainder 7 | let quotient = Math.floor(dividend / divisor); 8 | let remainder = dividend % divisor; 9 | // Returns both in an object 10 | return { quotient, remainder }; 11 | } 12 | 13 | // Trying it with 10 divided by 3 14 | console.log(divideAndRemainder(10, 3)); // Shows { quotient: 3, remainder: 1 } 15 | // It shows how many times 3 goes into 10, and what's left over. 16 | -------------------------------------------------------------------------------- /day-05/q15/main.js: -------------------------------------------------------------------------------- 1 | // Q14 Answer: 2 | var guests = ["Albert Einstein", "Marie Curie", "Nikola Tesla"]; 3 | guests.forEach(function (guest) { 4 | console.log("Dear ".concat(guest, ", would you like to join me for dinner?")); 5 | }); 6 | // Q15 Answer: 7 | var unableToAttend = "Nikola Tesla"; 8 | console.log("".concat(unableToAttend, " can't make it to dinner.")); 9 | // Replace the guest 10 | var newGuest = "Leonardo da Vinci"; 11 | guests[guests.indexOf(unableToAttend)] = newGuest; 12 | // New invitations 13 | guests.forEach(function (guest) { 14 | console.log("Dear ".concat(guest, ", would you like to join me for dinner?")); 15 | }); 16 | -------------------------------------------------------------------------------- /day-66/TS-Type-System-Concepts/04-Type-Alias.ts: -------------------------------------------------------------------------------- 1 | /************** 2 | * TYPE ALIAS * 3 | **************/ 4 | 5 | type MyString = string; 6 | 7 | let myName: MyString = "Glitcher"; 8 | 9 | type MyStringOrNumber = string | number; 10 | 11 | let myValue: MyStringOrNumber = 10; 12 | 13 | // another example 14 | type Employee = { 15 | name: string; 16 | age: number; 17 | email?: string; 18 | }; 19 | 20 | const alice: Employee = { 21 | name: "Alice", 22 | age: 30, 23 | email: "alice@example.com", 24 | }; 25 | 26 | const bob: Employee = { 27 | name: "Bob", 28 | age: 25, 29 | }; 30 | 31 | console.log(alice); 32 | console.log(bob); 33 | -------------------------------------------------------------------------------- /day-41/q123/main.ts: -------------------------------------------------------------------------------- 1 | // This function iterates through a string and logs each character until it finds a vowel 2 | function logUntilVowel(str: string): void { 3 | const vowels = "aeiouAEIOU"; 4 | for (const char of str) { 5 | if (vowels.includes(char)) { 6 | console.log(`First vowel found: ${char}`); 7 | break; // Stops the loop at the first vowel found 8 | } 9 | console.log(char); // Logs each character until a vowel is encountered 10 | } 11 | } 12 | 13 | logUntilVowel("syzygy"); // Logs 's', 'y', 'z', 'y', and then 'First vowel found: y' 14 | // Demonstrates iterating through a string and stopping at the first vowel. 15 | -------------------------------------------------------------------------------- /day-48/q143/main.ts: -------------------------------------------------------------------------------- 1 | // Creates a Promise that either resolves or rejects based on a condition 2 | const conditionalPromise = new Promise((resolve, reject) => { 3 | const success = Math.random() > 0.5; // Randomly choose success or failure 4 | if (success) { 5 | resolve("Success!"); 6 | } else { 7 | reject(new Error("Failure")); 8 | } 9 | }); 10 | 11 | conditionalPromise 12 | .then((result) => console.log(result)) // Handles a successful resolution 13 | .catch((error) => console.log(error.message)); // Handles a rejection 14 | // This code will randomly log either "Success!" or "Failure" based on the outcome of the promise. 15 | -------------------------------------------------------------------------------- /day-26/README.md: -------------------------------------------------------------------------------- 1 | # Day-26 of `100-Days-Of-Code` Challenge 2 | 3 | **Question 76:** Function Parameters and Return Values: Create a function that takes two numbers as parameters, adds them together, and returns the result. Show how you can call this function and log the result. 4 | 5 | **Question 77:** Default Parameters: Write a function that greets a user. It should take the user's name as a parameter and say hello. If no name is given, it should greet an anonymous user. 6 | 7 | **Question 78:** Function Expressions vs. Function Declarations: Compare function expressions and declarations by creating one of each that performs the same task, such as squaring a number. -------------------------------------------------------------------------------- /day-70/TS-Interface/04-HTMLImageElement.ts: -------------------------------------------------------------------------------- 1 | /******************** 2 | * HTMLIMAGEELEMENT * 3 | ********************/ 4 | 5 | // This example is for educational purposes, but it is not going to work. 6 | const imgElement: HTMLImageElement = document.createElement("img"); 7 | imgElement.src = "image.jpg"; 8 | imgElement.alt = "My Image"; 9 | 10 | if (imgElement.complete) { 11 | console.log(`Image dimensions: ${imgElement.naturalWidth}x${imgElement.naturalHeight}`); 12 | } else { 13 | imgElement.addEventListener("load", () => { 14 | console.log(`Image dimensions: ${imgElement.naturalWidth}x${imgElement.naturalHeight}`); 15 | }); 16 | } 17 | -------------------------------------------------------------------------------- /day-22/README.md: -------------------------------------------------------------------------------- 1 | # Day-22 of `100-Days-Of-Code` Challenge 2 | 3 | **Q64** - Combine Strings and Numbers: Write a function that merges a piece of text with a number. For example, if provided with "Age: " and 30, it should give back "Age: 30". 4 | 5 | **Q65** - Determine the Remainder: Make a function that gets two numbers and shows the leftover from dividing them using the `%` sign. For example, `remainder(5, 2)` should give `1`. 6 | 7 | **Q66** - Logical AND Verification: Create a function that checks two boolean (true or false) values. It should only say `true` if both are true, using the `&&` operator. For instance, `checkBothTrue(true, false)` should be `false`. 8 | -------------------------------------------------------------------------------- /day-42/q126/main.js: -------------------------------------------------------------------------------- 1 | // Demonstrates 'this' behavior change in a nested function 2 | var myObject = { 3 | property: "Value", 4 | outerMethod: function () { 5 | var _this = this; 6 | console.log(this.property); // Works as expected, logs "Value" 7 | var innerMethod = function () { 8 | console.log(_this.property); // Still accesses myObject's 'property' due to arrow function capturing 'this' from outer scope 9 | }; 10 | innerMethod(); 11 | }, 12 | }; 13 | myObject.outerMethod(); 14 | // This example shows that using an arrow function for the inner method preserves the 'this' context from the outer method. 15 | -------------------------------------------------------------------------------- /day-24/README.md: -------------------------------------------------------------------------------- 1 | # Day-24 of `100-Days-Of-Code` Challenge 2 | 3 | **Question 70:** Understanding let in Loops: Write a function that uses a loop with the let keyword to print numbers from 1 to 5. Explain how the let keyword affects the visibility of the loop variable. 4 | 5 | **Question 71:** Compare `let` and `const`: Create two examples where `let` allows reassignment but `const` does not. Try to reassign a `const`-declared variable and catch the error. 6 | 7 | **Question 72:** Block Scope with `let` and `const`: Demonstrate block scope by creating a code block with `{}` that uses both `let` and `const`. Show how variables declared inside the block are not accessible outside of it. -------------------------------------------------------------------------------- /day-70/TS-Interface/02-Interface-Method-And-Parameters.ts: -------------------------------------------------------------------------------- 1 | /*********************************** 2 | * INTERFACE METHOD AND PARAMETERS * 3 | ***********************************/ 4 | 5 | // Define an interface 'Person' with a method 'greet' 6 | interface PersonEx2 { 7 | name: string; 8 | age: number; 9 | greet(message: string): void; 10 | } 11 | 12 | // Create an object that adheres to the 'Person' interface 13 | const Sarah: PersonEx2 = { 14 | name: "Sarah", 15 | age: 30, 16 | greet(message: string) { 17 | console.log(`${this.name} says: ${message}`); 18 | }, 19 | }; 20 | 21 | Sarah.greet("Hello, TypeScript!"); // Output: Alice says: Hello, TypeScript! 22 | -------------------------------------------------------------------------------- /day-16/q48/main.js: -------------------------------------------------------------------------------- 1 | var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { 2 | if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { 3 | if (ar || !(i in from)) { 4 | if (!ar) ar = Array.prototype.slice.call(from, 0, i); 5 | ar[i] = from[i]; 6 | } 7 | } 8 | return to.concat(ar || Array.prototype.slice.call(from)); 9 | }; 10 | var pricesSet1 = [1200, 1500, 1100]; 11 | var pricesSet2 = [1000, 1300, 1600]; 12 | var combinedPrices = __spreadArray(__spreadArray([], pricesSet1, true), pricesSet2, true).sort(function (a, b) { return a - b; }); 13 | console.log(combinedPrices); 14 | -------------------------------------------------------------------------------- /day-06/q18/main.ts: -------------------------------------------------------------------------------- 1 | let places: string[] = ["New Zealand", "Iceland", "Japan", "Switzerland", "Norway"]; 2 | 3 | console.log("Original order:", places); 4 | 5 | console.log("Alphabetical order:", [...places].sort()); 6 | 7 | console.log("Original order:", places); 8 | 9 | console.log("Reverse alphabetical order:", [...places].sort().reverse()); 10 | 11 | console.log("Original order:", places); 12 | 13 | places.reverse(); 14 | console.log("Reversed order:", places); 15 | 16 | places.reverse(); 17 | console.log("Original order:", places); 18 | 19 | places.sort(); 20 | console.log("Alphabetical order:", places); 21 | 22 | places.reverse(); 23 | console.log("Reverse alphabetical order:", places); -------------------------------------------------------------------------------- /day-24/q72/main.ts: -------------------------------------------------------------------------------- 1 | // Demonstrating block scope 2 | { 3 | let blockLet = "visible inside the block"; 4 | const blockConst = "also only inside the block"; 5 | console.log(blockLet); // Works fine here 6 | console.log(blockConst); // Also works fine here 7 | } 8 | 9 | try { 10 | console.log(blockLet); // This will fail 11 | } catch (error) { 12 | console.log("`blockLet` is not accessible outside the block."); 13 | } 14 | 15 | try { 16 | console.log(blockConst); // This will also fail 17 | } catch (error) { 18 | console.log("`blockConst` is not accessible outside the block."); 19 | } 20 | // This shows that `let` and `const` keep variables safe inside the block where they're defined. 21 | -------------------------------------------------------------------------------- /day-16/README.md: -------------------------------------------------------------------------------- 1 | # Day-16 of `100-Days-Of-Code` Challenge 2 | 3 | **Q46** - Enhanced Laptop Object: Construct an object for a laptop including properties make, model, year, and a method describe() that logs a sentence about the laptop. 4 | 5 | **Q47** - Array Destructuring: Given an array of objects representing different laptops, each with properties `make`, `model`, and `year`, use array destructuring to assign the first and second laptops to variables. Then, log these variables. 6 | 7 | **Q48** - Combining Arrays with Spread Operator: Suppose you're comparing prices of two different sets of laptops. Use the spread operator to combine these arrays into a single array sorted in ascending order, then log the result. -------------------------------------------------------------------------------- /day-48/q143/main.js: -------------------------------------------------------------------------------- 1 | // Creates a Promise that either resolves or rejects based on a condition 2 | var conditionalPromise = new Promise(function (resolve, reject) { 3 | var success = Math.random() > 0.5; // Randomly choose success or failure 4 | if (success) { 5 | resolve("Success!"); 6 | } 7 | else { 8 | reject(new Error("Failure")); 9 | } 10 | }); 11 | conditionalPromise 12 | .then(function (result) { return console.log(result); }) // Handles a successful resolution 13 | .catch(function (error) { return console.log(error.message); }); // Handles a rejection 14 | // This code will randomly log either "Success!" or "Failure" based on the outcome of the promise. 15 | -------------------------------------------------------------------------------- /day-24/q72/main.js: -------------------------------------------------------------------------------- 1 | // Demonstrating block scope 2 | { 3 | var blockLet = "visible inside the block"; 4 | var blockConst = "also only inside the block"; 5 | console.log(blockLet); // Works fine here 6 | console.log(blockConst); // Also works fine here 7 | } 8 | try { 9 | console.log(blockLet); // This will fail 10 | } 11 | catch (error) { 12 | console.log("`blockLet` is not accessible outside the block."); 13 | } 14 | try { 15 | console.log(blockConst); // This will also fail 16 | } 17 | catch (error) { 18 | console.log("`blockConst` is not accessible outside the block."); 19 | } 20 | // This shows that `let` and `const` keep variables safe inside the block where they're defined. 21 | -------------------------------------------------------------------------------- /day-15/q43/main.js: -------------------------------------------------------------------------------- 1 | var magicians = ["Alice", "David", "Chris"]; 2 | function make_great(magicians) { 3 | var greatMagicians = []; 4 | magicians.forEach(function (magician) { 5 | greatMagicians.push("".concat(magician, " the Great")); 6 | }); 7 | return greatMagicians; 8 | } 9 | function show_magicians(magicians) { 10 | magicians.forEach(function (magician) { 11 | console.log(magician); 12 | }); 13 | } 14 | var greatMagicians = make_great(magicians.slice()); // Creates a new modified array 15 | console.log("Original magicians:"); 16 | show_magicians(magicians); // Shows original names 17 | console.log("Great magicians:"); 18 | show_magicians(greatMagicians); // Shows modified names 19 | -------------------------------------------------------------------------------- /day-33/q99/main.js: -------------------------------------------------------------------------------- 1 | // Generates a Date object for the next occurrence of a specific birthday 2 | function getNextBirthday(month, day) { 3 | var today = new Date(); 4 | var year = today.getFullYear(); 5 | var birthday = new Date(year, month - 1, day); // Months are 0-indexed 6 | if (birthday < today) { 7 | // If the birthday this year has already passed, use next year's date 8 | birthday.setFullYear(year + 1); 9 | } 10 | return birthday; 11 | } 12 | // Replace with your birth month and day 13 | var nextBirthday = getNextBirthday(12, 25); // Example: December 25th 14 | console.log("Next birthday on:", nextBirthday.toLocaleDateString()); 15 | // Shows the date of the next birthday. 16 | -------------------------------------------------------------------------------- /day-41/q123/main.js: -------------------------------------------------------------------------------- 1 | // This function iterates through a string and logs each character until it finds a vowel 2 | function logUntilVowel(str) { 3 | var vowels = "aeiouAEIOU"; 4 | for (var _i = 0, str_1 = str; _i < str_1.length; _i++) { 5 | var char = str_1[_i]; 6 | if (vowels.includes(char)) { 7 | console.log("First vowel found: ".concat(char)); 8 | break; // Stops the loop at the first vowel found 9 | } 10 | console.log(char); // Logs each character until a vowel is encountered 11 | } 12 | } 13 | logUntilVowel("syzygy"); // Logs 's', 'y', 'z', 'y', and then 'First vowel found: y' 14 | // Demonstrates iterating through a string and stopping at the first vowel. 15 | -------------------------------------------------------------------------------- /day-72/TS-Generics/01-Generics-Intro.ts: -------------------------------------------------------------------------------- 1 | /****************** 2 | * GENERICS INTRO * 3 | ******************/ 4 | 5 | // A generic function that returns the input value as is 6 | function returnType(val: T): T { 7 | return val; 8 | } 9 | 10 | // Usage of the generic function with different types 11 | const numValue: number = returnType(100); 12 | const strValue: string = returnType("Elzero"); 13 | const boolValue: boolean = returnType(true); 14 | const arrValue: number[] = returnType([1, 2, 3, 4]); 15 | 16 | console.log(`Number Value: ${numValue}`); 17 | console.log(`String Value: ${strValue}`); 18 | console.log(`Boolean Value: ${boolValue}`); 19 | console.log(`Array Value: ${arrValue}`); 20 | -------------------------------------------------------------------------------- /day-15/q43/main.ts: -------------------------------------------------------------------------------- 1 | let magicians: string[] = ["Alice", "David", "Chris"]; 2 | 3 | function make_great(magicians: string[]): string[] { 4 | let greatMagicians = []; 5 | magicians.forEach((magician) => { 6 | greatMagicians.push(`${magician} the Great`); 7 | }); 8 | return greatMagicians; 9 | } 10 | 11 | function show_magicians(magicians: string[]) { 12 | magicians.forEach((magician) => { 13 | console.log(magician); 14 | }); 15 | } 16 | 17 | let greatMagicians = make_great(magicians.slice()); // Creates a new modified array 18 | console.log("Original magicians:"); 19 | show_magicians(magicians); // Shows original names 20 | console.log("Great magicians:"); 21 | show_magicians(greatMagicians); // Shows modified names 22 | -------------------------------------------------------------------------------- /day-33/q99/main.ts: -------------------------------------------------------------------------------- 1 | // Generates a Date object for the next occurrence of a specific birthday 2 | function getNextBirthday(month: number, day: number): Date { 3 | const today = new Date(); 4 | let year = today.getFullYear(); 5 | const birthday = new Date(year, month - 1, day); // Months are 0-indexed 6 | if (birthday < today) { 7 | // If the birthday this year has already passed, use next year's date 8 | birthday.setFullYear(year + 1); 9 | } 10 | return birthday; 11 | } 12 | 13 | // Replace with your birth month and day 14 | const nextBirthday = getNextBirthday(12, 25); // Example: December 25th 15 | console.log("Next birthday on:", nextBirthday.toLocaleDateString()); 16 | // Shows the date of the next birthday. 17 | -------------------------------------------------------------------------------- /day-18/README.md: -------------------------------------------------------------------------------- 1 | # Day-18 of `100-Days-Of-Code` Challenge 2 | 3 | **Q52** - Make a Smartphone Object: Create a simple way to keep track of a smartphone's details. Include its brand, model, and other key features like how much storage it has, the size of its screen, and how long its battery lasts. 4 | 5 | **Q53** - Pulling Apart a Nested Object: Imagine you have a list inside another list that shows what a computer programmer knows, like coding languages, tools, and software frameworks. Find a way to get three specific skills from this list and show them. 6 | 7 | **Q54** - Making Flexible Object Keys: Learn how to set up a list where you can change the name of each section based on what you need at that moment, like adjusting labels based on user choices. -------------------------------------------------------------------------------- /day-39/q117/main.ts: -------------------------------------------------------------------------------- 1 | // This function evaluates a grade and logs the corresponding remark 2 | function evaluateGrade(grade: string): void { 3 | switch (grade) { 4 | case "A": 5 | console.log("Excellent"); 6 | break; 7 | case "B": 8 | console.log("Good"); 9 | break; 10 | case "C": 11 | console.log("Fair"); 12 | break; 13 | case "D": 14 | console.log("Poor"); 15 | break; 16 | case "F": 17 | console.log("Fail"); 18 | break; 19 | default: 20 | console.log("Invalid grade"); 21 | break; 22 | } 23 | } 24 | 25 | evaluateGrade("B"); // Outputs: Good 26 | // Uses a switch statement to evaluate the grade and defaults to "Invalid grade" if no match is found. 27 | -------------------------------------------------------------------------------- /day-39/q116/main.ts: -------------------------------------------------------------------------------- 1 | // This function logs the season based on the month 2 | function logSeason(month: number): void { 3 | switch (month) { 4 | case 12: 5 | case 1: 6 | case 2: 7 | console.log("Winter"); 8 | break; 9 | case 3: 10 | case 4: 11 | case 5: 12 | console.log("Spring"); 13 | break; 14 | case 6: 15 | case 7: 16 | case 8: 17 | console.log("Summer"); 18 | break; 19 | case 9: 20 | case 10: 21 | case 11: 22 | console.log("Fall"); 23 | break; 24 | default: 25 | console.log("Invalid month"); 26 | break; 27 | } 28 | } 29 | 30 | logSeason(4); // Outputs: Spring 31 | // Multiple cases share the same code block to represent each season. 32 | -------------------------------------------------------------------------------- /day-70/TS-Interface/03-ReOpen-The-Interface-And-Use-Cases.ts: -------------------------------------------------------------------------------- 1 | /************************************** 2 | * REOPEN THE INTERFACE AND USE CASES * 3 | **************************************/ 4 | 5 | // Homepage Interface Declaration 6 | interface Settings { 7 | readonly theme: boolean; 8 | font: string; 9 | } 10 | 11 | // Articles Page Interface Reopening 12 | interface Settings { 13 | sidebar: boolean; 14 | } 15 | 16 | // Contact Page Interface Reopening 17 | interface Settings { 18 | external: boolean; 19 | } 20 | 21 | // Create an object 'userSettings' that adheres to the merged 'Settings' interface 22 | let userSettings: Settings = { 23 | theme: true, 24 | font: "Open Sans", 25 | sidebar: false, 26 | external: true, 27 | }; 28 | -------------------------------------------------------------------------------- /day-25/README.md: -------------------------------------------------------------------------------- 1 | # Day-25 of `100-Days-Of-Code` Challenge 2 | 3 | **Question 73:** Assigning and Updating Variables: Create a function where you declare a variable using let and assign an initial value. Then, update its value within the same function and log both the initial and updated values. 4 | 5 | **Question 74:** Swapping Variables: Demonstrate how to swap the values of two variables. Start with variables `a = 5` and `b = 10`, then swap their values so that `a` becomes `10` and `b` becomes `5`. 6 | 7 | **Question 75:** Compound Assignment Operators: Use compound assignment operators to simplify arithmetic operations. Start with `x = 4` and perform a series of operations (addition, subtraction, multiplication, division) on `x` using compound operators. 8 | -------------------------------------------------------------------------------- /day-25/q75/main.js: -------------------------------------------------------------------------------- 1 | // This function uses compound assignment operators for different operations 2 | function useCompoundOperators() { 3 | var x = 4; // Starts with x equal to 4 4 | console.log("Initial x:", x); 5 | x += 2; // Adds 2 to x 6 | console.log("After addition:", x); // Shows x after addition 7 | x -= 1; // Subtracts 1 from x 8 | console.log("After subtraction:", x); // Shows x after subtraction 9 | x *= 3; // Multiplies x by 3 10 | console.log("After multiplication:", x); // Shows x after multiplication 11 | x /= 2; // Divides x by 2 12 | console.log("After division:", x); // Shows x after division 13 | } 14 | useCompoundOperators(); 15 | // We simplify arithmetic operations on x using compound assignment operators, like a shortcut. 16 | -------------------------------------------------------------------------------- /day-25/q75/main.ts: -------------------------------------------------------------------------------- 1 | // This function uses compound assignment operators for different operations 2 | function useCompoundOperators() { 3 | let x = 4; // Starts with x equal to 4 4 | console.log("Initial x:", x); 5 | 6 | x += 2; // Adds 2 to x 7 | console.log("After addition:", x); // Shows x after addition 8 | 9 | x -= 1; // Subtracts 1 from x 10 | console.log("After subtraction:", x); // Shows x after subtraction 11 | 12 | x *= 3; // Multiplies x by 3 13 | console.log("After multiplication:", x); // Shows x after multiplication 14 | 15 | x /= 2; // Divides x by 2 16 | console.log("After division:", x); // Shows x after division 17 | } 18 | 19 | useCompoundOperators(); 20 | // We simplify arithmetic operations on x using compound assignment operators, like a shortcut. 21 | -------------------------------------------------------------------------------- /day-21/q63/main.ts: -------------------------------------------------------------------------------- 1 | // Creating a custom type (type alias) for shapes that could be circles or rectangles 2 | type Shape = { 3 | kind: "circle" | "rectangle"; 4 | radius?: number; // Only for circles 5 | width?: number; // Only for rectangles 6 | height?: number; // Only for rectangles 7 | }; 8 | 9 | // Describing a circle using our Shape type 10 | let circle: Shape = { 11 | kind: "circle", 12 | radius: 5, 13 | }; 14 | 15 | // Describing a rectangle using our Shape type 16 | let rectangle: Shape = { 17 | kind: "rectangle", 18 | width: 10, 19 | height: 20, 20 | }; 21 | 22 | // Showing what we described 23 | console.log(circle); // Here's the circle 24 | console.log(rectangle); // And here's the rectangle 25 | // We made a flexible program that can describe different shapes in detail. 26 | -------------------------------------------------------------------------------- /day-04/README.md: -------------------------------------------------------------------------------- 1 | # Day-04 of `100-Days-Of-Code` Challenge 2 | 3 | **Q10** - Adding Comments: Choose two of the programs you’ve written, and add at least one comment to each. If you don’t have anything specific to write because your programs are too simple at this point, just add your name and the current date at the top of each program file. Then write one sentence describing what the program does. 4 | 5 | **Q11** - Names: Store the names of a few of your friends in a array called names. Print each person’s name by accessing each element in the list, one at a time. 6 | 7 | **Q12** - Greetings: Start with the array you used in Exercise 11, but instead of just printing each person’s name, print a message to them. The text of each message should be the same, but each message should be personalized with the person’s name. 8 | 9 | -------------------------------------------------------------------------------- /day-39/q117/main.js: -------------------------------------------------------------------------------- 1 | // This function evaluates a grade and logs the corresponding remark 2 | function evaluateGrade(grade) { 3 | switch (grade) { 4 | case "A": 5 | console.log("Excellent"); 6 | break; 7 | case "B": 8 | console.log("Good"); 9 | break; 10 | case "C": 11 | console.log("Fair"); 12 | break; 13 | case "D": 14 | console.log("Poor"); 15 | break; 16 | case "F": 17 | console.log("Fail"); 18 | break; 19 | default: 20 | console.log("Invalid grade"); 21 | break; 22 | } 23 | } 24 | evaluateGrade("B"); // Outputs: Good 25 | // Uses a switch statement to evaluate the grade and defaults to "Invalid grade" if no match is found. 26 | -------------------------------------------------------------------------------- /day-43/q129/main.ts: -------------------------------------------------------------------------------- 1 | // Demonstrating 'this' in traditional vs. arrow functions 2 | const traditionalVsArrow = { 3 | value: "traditionalVsArrow value", 4 | traditionalFunction: function () { 5 | console.log("Traditional function:", this.value); // 'this' refers to traditionalVsArrow object 6 | }, 7 | arrowFunction: () => { 8 | console.log("Arrow function:", this.value); // 'this' is not bound to traditionalVsArrow object but to the scope in which traditionalVsArrow was defined 9 | }, 10 | }; 11 | 12 | traditionalVsArrow.traditionalFunction(); // Logs "traditionalVsArrow value" 13 | traditionalVsArrow.arrowFunction(); // Likely undefined, depending on the outer scope's 'this.value' 14 | // This code snippet illustrates the difference in how 'this' is determined in traditional functions versus arrow functions. 15 | -------------------------------------------------------------------------------- /day-39/q116/main.js: -------------------------------------------------------------------------------- 1 | // This function logs the season based on the month 2 | function logSeason(month) { 3 | switch (month) { 4 | case 12: 5 | case 1: 6 | case 2: 7 | console.log("Winter"); 8 | break; 9 | case 3: 10 | case 4: 11 | case 5: 12 | console.log("Spring"); 13 | break; 14 | case 6: 15 | case 7: 16 | case 8: 17 | console.log("Summer"); 18 | break; 19 | case 9: 20 | case 10: 21 | case 11: 22 | console.log("Fall"); 23 | break; 24 | default: 25 | console.log("Invalid month"); 26 | break; 27 | } 28 | } 29 | logSeason(4); // Outputs: Spring 30 | // Multiple cases share the same code block to represent each season. 31 | -------------------------------------------------------------------------------- /day-43/q129/main.js: -------------------------------------------------------------------------------- 1 | var _this = this; 2 | // Demonstrating 'this' in traditional vs. arrow functions 3 | var traditionalVsArrow = { 4 | value: "traditionalVsArrow value", 5 | traditionalFunction: function () { 6 | console.log("Traditional function:", this.value); // 'this' refers to traditionalVsArrow object 7 | }, 8 | arrowFunction: function () { 9 | console.log("Arrow function:", _this.value); // 'this' is not bound to traditionalVsArrow object but to the scope in which traditionalVsArrow was defined 10 | }, 11 | }; 12 | traditionalVsArrow.traditionalFunction(); // Logs "traditionalVsArrow value" 13 | traditionalVsArrow.arrowFunction(); // Likely undefined, depending on the outer scope's 'this.value' 14 | // This code snippet illustrates the difference in how 'this' is determined in traditional functions versus arrow functions. 15 | -------------------------------------------------------------------------------- /day-71/TS-Class/01-Class-Type-Annotations.ts: -------------------------------------------------------------------------------- 1 | /************************** 2 | * CLASS TYPE ANNOTATIONS * 3 | **************************/ 4 | 5 | class Product { 6 | // Property type annotations 7 | id: number; 8 | name: string; 9 | price: number; 10 | 11 | constructor(id: number, name: string, price: number) { 12 | // Constructor parameter type annotations 13 | this.id = id; 14 | this.name = name; 15 | this.price = price; 16 | } 17 | 18 | // Method type annotations 19 | getProductInfo(): string { 20 | return `ID: ${this.id}, Name: ${this.name}, Price: $${this.price}`; 21 | } 22 | } 23 | 24 | // Create an instance of the Product class 25 | const product1 = new Product(1, "Widget", 20.0); 26 | 27 | // Access class properties and call a method 28 | console.log(product1.getProductInfo()); // Output: ID: 1, Name: Widget, Price: $20 29 | -------------------------------------------------------------------------------- /day-39/q115/main.ts: -------------------------------------------------------------------------------- 1 | // This function logs the day of the week based on a number (1-7) 2 | function logDayOfWeek(dayNumber: number): void { 3 | switch (dayNumber) { 4 | case 1: 5 | console.log("Sunday"); 6 | break; 7 | case 2: 8 | console.log("Monday"); 9 | break; 10 | case 3: 11 | console.log("Tuesday"); 12 | break; 13 | case 4: 14 | console.log("Wednesday"); 15 | break; 16 | case 5: 17 | console.log("Thursday"); 18 | break; 19 | case 6: 20 | console.log("Friday"); 21 | break; 22 | case 7: 23 | console.log("Saturday"); 24 | break; 25 | default: 26 | console.log("Invalid day number"); 27 | break; 28 | } 29 | } 30 | 31 | logDayOfWeek(3); // Outputs: Tuesday 32 | // Uses a switch statement to select the appropriate day based on the provided number. 33 | -------------------------------------------------------------------------------- /day-65/TS-Function/02-Optional-And-Default-Parameter.ts: -------------------------------------------------------------------------------- 1 | /********************************** 2 | * OPTIONAL AND DEFAULT PARAMETER * 3 | **********************************/ 4 | 5 | // Optional Parameters: 6 | function greetOptional(name: string, age?: number) { 7 | if (age !== undefined) { 8 | console.log(`Hello, ${name}! You are ${age} years old.`); 9 | } else { 10 | console.log(`Hello, ${name}!`); 11 | } 12 | } 13 | 14 | greetOptional("Alice"); // Output: "Hello, Alice!" 15 | greetOptional("Bob", 30); // Output: "Hello, Bob! You are 30 years old." 16 | 17 | // Default Parameters: 18 | function greetDefault(name: string, age: number = 25) { 19 | console.log(`Hello, ${name}! You are ${age} years old.`); 20 | } 21 | 22 | greetDefault("Alice"); // Output: "Hello, Alice! You are 25 years old." 23 | greetDefault("Bob", 30); // Output: "Hello, Bob! You are 30 years old." 24 | -------------------------------------------------------------------------------- /day-49/q147/main.js: -------------------------------------------------------------------------------- 1 | // Function that uses a callback pattern, including error handling 2 | function fetchData(callback) { 3 | // Simulating an error condition 4 | var error = new Error("Failed to fetch data"); 5 | var data = "Some data"; 6 | // Simulate fetching data with a chance of error 7 | if (Math.random() > 0.5) { 8 | callback(null, data); // No error, data is fetched successfully 9 | } 10 | else { 11 | callback(error); // Passes error to the callback 12 | } 13 | } 14 | // Using the fetchData function with error handling in the callback 15 | fetchData(function (error, data) { 16 | if (error) { 17 | console.error(error.message); // Handles the error 18 | } 19 | else { 20 | console.log(data); // Processes the data 21 | } 22 | }); 23 | // Demonstrates a callback pattern where errors are handled gracefully. 24 | -------------------------------------------------------------------------------- /day-72/TS-Generics/03-Generics-Classes.ts: -------------------------------------------------------------------------------- 1 | /******************** 2 | * GENERICS CLASSES * 3 | ********************/ 4 | 5 | // Generic Class `User` 6 | class User { 7 | constructor(public value: T) {} 8 | 9 | // Method that takes a message of type `T` and displays it along with the `value` property 10 | show(msg: T): void { 11 | console.log(`${msg} - ${this.value}`); 12 | } 13 | } 14 | 15 | // Creating an instance of `User` with a specific type parameter (string) 16 | let userOne = new User("Elzero"); 17 | console.log(userOne.value); // Outputs: "Elzero" 18 | userOne.show("Message"); // Outputs: "Message - Elzero" 19 | 20 | // Creating an instance of `User` with a type parameter that can be a number or a string 21 | let userTwo = new User(100); 22 | console.log(userTwo.value); // Outputs: 100 23 | userTwo.show("Message"); // Outputs: "Message - 100" 24 | -------------------------------------------------------------------------------- /day-02/README.md: -------------------------------------------------------------------------------- 1 | # Day-02 of `100-Days-Of-Code` Challenge 2 | 3 | **Q4** - Famous Quote: Find a quote from a famous person you admire. Print the quote and the name of its author. Your output should look something like the following, including the quotation marks: 4 | 5 | Albert Einstein once said, “A person who never made a mistake never tried anything new.” 6 | 7 | **Q5** - Famous Quote 2: Repeat Exercise 4, but this time store the famous person’s name in a variable called famous_person. Then compose your message and store it in a new variable called message. Print your message. 8 | 9 | 10 | **Q6** - Stripping Names: Store a person’s name, and include some whitespace characters at the beginning and end of the name. Make sure you use each character combination, "\t" and "\n", at least once. Print the name once, so the whitespace around the name is displayed. Then print the name after striping the white spaces. -------------------------------------------------------------------------------- /day-49/q147/main.ts: -------------------------------------------------------------------------------- 1 | // Function that uses a callback pattern, including error handling 2 | function fetchData( 3 | callback: (error: Error | null, data?: string) => void 4 | ): void { 5 | // Simulating an error condition 6 | const error = new Error("Failed to fetch data"); 7 | const data = "Some data"; 8 | 9 | // Simulate fetching data with a chance of error 10 | if (Math.random() > 0.5) { 11 | callback(null, data); // No error, data is fetched successfully 12 | } else { 13 | callback(error); // Passes error to the callback 14 | } 15 | } 16 | 17 | // Using the fetchData function with error handling in the callback 18 | fetchData((error, data) => { 19 | if (error) { 20 | console.error(error.message); // Handles the error 21 | } else { 22 | console.log(data); // Processes the data 23 | } 24 | }); 25 | // Demonstrates a callback pattern where errors are handled gracefully. 26 | -------------------------------------------------------------------------------- /day-64/TS-Object/01-Type-Annotations-With-Objects.ts: -------------------------------------------------------------------------------- 1 | /********************************* 2 | * TYPE ANNOTATIONS WITH OBJECTS * 3 | *********************************/ 4 | 5 | let personExOne: { 6 | name: string; 7 | age: number; 8 | jobTitle?: string; 9 | address: { 10 | street: string; 11 | city: string; 12 | }; 13 | }; 14 | 15 | personExOne = { 16 | name: "Alice", 17 | age: 30, 18 | jobTitle: "Engineer", 19 | address: { 20 | street: "123 Main St", 21 | city: "Wonderland", 22 | }, 23 | }; 24 | 25 | // And there is yet another method 26 | let personExTwo: { 27 | name: string; 28 | age: number; 29 | jobTitle?: string; 30 | address: { 31 | street: string; 32 | city: string; 33 | }; 34 | } = { 35 | name: "Alice", 36 | age: 30, 37 | jobTitle: "Engineer", 38 | address: { 39 | street: "123 Main St", 40 | city: "Wonderland", 41 | }, 42 | }; 43 | -------------------------------------------------------------------------------- /day-06/q17/main.ts: -------------------------------------------------------------------------------- 1 | // Q16 Answer: 2 | let guests: string[] = ["Albert Einstein", "Marie Curie", "Leonardo da Vinci"]; 3 | console.log("Great news! I found a bigger dinner table!"); 4 | 5 | // Adding more guests 6 | guests.unshift("Isaac Newton"); 7 | guests.splice(guests.length / 2, 0, "Charles Darwin"); 8 | guests.push("Ada Lovelace"); 9 | 10 | guests.forEach(guest => { 11 | console.log(`Dear ${guest}, would you like to join me for dinner?`); 12 | }); 13 | 14 | // Q17 Answer: 15 | console.log("Unfortunately, I can only invite two people for dinner."); 16 | 17 | while (guests.length > 2) { 18 | let removedGuest = guests.pop(); 19 | console.log(`Sorry, ${removedGuest}, I can't invite you to dinner.`); 20 | } 21 | 22 | guests.forEach(guest => { 23 | console.log(`Dear ${guest}, you're still invited to dinner.`); 24 | }); 25 | 26 | guests.splice(0, guests.length); 27 | console.log(guests); // Shows an empty list --------------------------------------------------------------------------------