29 | }
--------------------------------------------------------------------------------
/week-6/1-use-memo/src/components/Assignment1.jsx:
--------------------------------------------------------------------------------
1 | import { useMemo, useState } from "react";
2 |
3 | // In this assignment, your task is to create a component that performs an expensive calculation (finding the factorial) based on a user input.
4 | // Use useMemo to ensure that the calculation is only recomputed when the input changes, not on every render.
5 |
6 | export function Assignment1() {
7 | const [input, setInput] = useState(0);
8 | const expensiveValue = useMemo(() => {
9 | let value = 1;
10 | for (let i = 1; i <= input; i++) {
11 | value = value * i;
12 | }
13 | return value;
14 | }, [input]);
15 |
16 | return (
17 |
26 | }
--------------------------------------------------------------------------------
/week-1/basics/math.js:
--------------------------------------------------------------------------------
1 | function mathMethods(value) {
2 | console.log("Original Value:", value);
3 |
4 | let rounded = Math.round(value);
5 | console.log("After round():", rounded);
6 |
7 | let ceiling = Math.ceil(value);
8 | console.log("After ceil():", ceiling);
9 |
10 | let flooring = Math.floor(value);
11 | console.log("After floor():", flooring);
12 |
13 | let randomValue = Math.random();
14 | console.log("After random():", randomValue);
15 |
16 | let maxValue = Math.max(5, 10, 15);
17 | console.log("After max():", maxValue);
18 |
19 | let minValue = Math.min(5, 10, 15);
20 | console.log("After min():", minValue);
21 |
22 | let powerOfTwo = Math.pow(value, 2);
23 | console.log("After pow():", powerOfTwo);
24 |
25 | let squareRoot = Math.sqrt(value);
26 | console.log("After sqrt():", squareRoot);
27 | }
28 |
29 | // Example Usage for Math Methods
30 | mathMethods(4.56);
31 | mathMethods(9);
32 | mathMethods(25);
33 |
--------------------------------------------------------------------------------
/week-1/problems/easy/anagram.js:
--------------------------------------------------------------------------------
1 | /*
2 | Write a function `isAnagram` which takes 2 parameters and returns true/false if those are anagrams or not.
3 | What's Anagram?
4 | - A word, phrase, or name formed by rearranging the letters of another, such as spar, formed from rasp.
5 | */
6 |
7 | function isAnagram(str1, str2) {
8 | const formattedStr1 = str1.replace(/\s/g, "").toLowerCase();
9 | const formattedStr2 = str2.replace(/\s/g, "").toLowerCase();
10 |
11 | // Check if the length of the strings is the same
12 | if (formattedStr1.length !== formattedStr2.length) {
13 | return false;
14 | }
15 |
16 | // Convert strings to arrays, sort them, and compare if they are equal
17 | const sortedStr1 = formattedStr1.split("").sort().join("");
18 | const sortedStr2 = formattedStr2.split("").sort().join("");
19 |
20 | return sortedStr1 === sortedStr2;
21 | }
22 |
23 | console.log(isAnagram("spar", "rasp"));
24 | module.exports = isAnagram;
25 |
--------------------------------------------------------------------------------
/week-1/problems/medium/times.js:
--------------------------------------------------------------------------------
1 | /*
2 | Write a function that calculates the time (in seconds) it takes for the JS code to calculate sum from 1 to n, given n as the input.
3 | Try running it for
4 | 1. Sum from 1-100
5 | 2. Sum from 1-100000
6 | 3. Sum from 1-1000000000
7 | Hint - use Date class exposed in JS
8 | There is no automated test for this one, this is more for you to understand time goes up as computation goes up
9 | */
10 |
11 | function calculateTime(n) {
12 | const startTime = new Date(); // Record the start time
13 |
14 | let sum = 0;
15 | for (let i = 1; i <= n; i++) {
16 | sum += i;
17 | }
18 |
19 | const endTime = new Date(); // Record the end time
20 |
21 | const elapsedTimeInSeconds = (endTime - startTime) / 1000; // Calculate elapsed time in seconds
22 | return elapsedTimeInSeconds;
23 | }
24 |
25 | console.log(calculateTime(100));
26 | console.log(calculateTime(100000));
27 | console.log(calculateTime(1000000000));
28 |
--------------------------------------------------------------------------------
/week-16/Auth/frontend/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "frontend",
3 | "private": true,
4 | "version": "0.0.0",
5 | "type": "module",
6 | "scripts": {
7 | "dev": "vite",
8 | "build": "tsc && vite build",
9 | "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
10 | "preview": "vite preview"
11 | },
12 | "dependencies": {
13 | "axios": "^1.6.8",
14 | "react": "^18.2.0",
15 | "react-dom": "^18.2.0",
16 | "react-router-dom": "^6.22.3"
17 | },
18 | "devDependencies": {
19 | "@types/react": "^18.2.64",
20 | "@types/react-dom": "^18.2.21",
21 | "@typescript-eslint/eslint-plugin": "^7.1.1",
22 | "@typescript-eslint/parser": "^7.1.1",
23 | "@vitejs/plugin-react": "^4.2.1",
24 | "eslint": "^8.57.0",
25 | "eslint-plugin-react-hooks": "^4.6.0",
26 | "eslint-plugin-react-refresh": "^0.4.5",
27 | "typescript": "^5.2.2",
28 | "vite": "^5.1.6"
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/week-3/middlewares/errCount.js:
--------------------------------------------------------------------------------
1 | // You have been given an express server which has a few endpoints.
2 | // Your task is to
3 | // 1. Ensure that if there is ever an exception, the end user sees a status code of 404
4 | // 2. Maintain the errorCount variable whose value should go up every time there is an exception in any endpoint
5 |
6 | const express = require("express");
7 |
8 | const app = express();
9 | let errorCount = 0;
10 |
11 | app.get("/user", function (req, res) {
12 | throw new Error("some error");
13 | // 500
14 | res.status(200).json({ name: "john" });
15 | });
16 |
17 | app.post("/user", function (req, res) {
18 | res.status(200).json({ msg: "created dummy user" });
19 | });
20 |
21 | app.get("/errorCount", function (req, res) {
22 | res.status(200).json({ errorCount });
23 | });
24 |
25 | // error handling middleware
26 | app.use(function (err, req, res, next) {
27 | res.status(404).send({});
28 | errorCount = errorCount + 1;
29 | });
30 |
31 | module.exports = app;
32 |
--------------------------------------------------------------------------------
/week-13/blog-stack/validateCommon/node_modules/zod/lib/external.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3 | if (k2 === undefined) k2 = k;
4 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5 | }) : (function(o, m, k, k2) {
6 | if (k2 === undefined) k2 = k;
7 | o[k2] = m[k];
8 | }));
9 | var __exportStar = (this && this.__exportStar) || function(m, exports) {
10 | for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11 | };
12 | Object.defineProperty(exports, "__esModule", { value: true });
13 | __exportStar(require("./errors"), exports);
14 | __exportStar(require("./helpers/parseUtil"), exports);
15 | __exportStar(require("./helpers/typeAliases"), exports);
16 | __exportStar(require("./helpers/util"), exports);
17 | __exportStar(require("./types"), exports);
18 | __exportStar(require("./ZodError"), exports);
19 |
--------------------------------------------------------------------------------
/week-2/async-js/hard/sleep-compeltely.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Write a function that halts the JS thread (make it busy wait) for a given number of milliseconds.
3 | * During this time the thread should not be able to do anything else.
4 | * the function should return a promise just like before
5 | */
6 |
7 | function sleep(milliseconds) {
8 | return new Promise((resolve) => {
9 | const startTime = Date.now();
10 |
11 | while (true) {
12 | const currentTime = Date.now();
13 | if (currentTime - startTime >= milliseconds) {
14 | resolve(`Slept for ${milliseconds} milliseconds`);
15 | console.log(`Slept for ${milliseconds} milliseconds`);
16 | break;
17 | }
18 | // Perform some CPU-intensive operation to keep the thread busy
19 | // Example: A dummy loop that consumes CPU cycles
20 | let a = 0;
21 | for (let i = 0; i < 100; i++) {
22 | a += 1;
23 | console.log(a);
24 | }
25 | }
26 | });
27 | }
28 |
29 | sleep(10000);
30 |
31 | module.exports = sleep;
32 |
--------------------------------------------------------------------------------
/week-7/paytm-fullstack/frontend/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "frontend",
3 | "private": true,
4 | "version": "0.0.0",
5 | "type": "module",
6 | "scripts": {
7 | "dev": "vite",
8 | "build": "vite build",
9 | "lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
10 | "preview": "vite preview"
11 | },
12 | "dependencies": {
13 | "axios": "^1.6.7",
14 | "ldrs": "^1.0.1",
15 | "prop-types": "^15.8.1",
16 | "react": "^18.2.0",
17 | "react-dom": "^18.2.0",
18 | "react-router-dom": "^6.22.1",
19 | "react-toastify": "^10.0.4"
20 | },
21 | "devDependencies": {
22 | "@types/react": "^18.2.55",
23 | "@types/react-dom": "^18.2.19",
24 | "@vitejs/plugin-react": "^4.2.1",
25 | "autoprefixer": "^10.4.17",
26 | "eslint": "^8.56.0",
27 | "eslint-plugin-react": "^7.33.2",
28 | "eslint-plugin-react-hooks": "^4.6.0",
29 | "eslint-plugin-react-refresh": "^0.4.5",
30 | "postcss": "^8.4.35",
31 | "tailwindcss": "^3.4.1",
32 | "vite": "^5.1.0"
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/week-3/mongo/db/index.js:
--------------------------------------------------------------------------------
1 | const mongoose = require("mongoose");
2 |
3 | mongoose
4 | .connect("Mongo_URL",
5 | {
6 | useNewUrlParser: true,
7 | }
8 | )
9 | .then(() => {
10 | console.log("Connected to MongoDB");
11 | })
12 | .catch((e) => {
13 | console.log(e);
14 | });
15 |
16 | // Define schemas
17 | const AdminSchema = new mongoose.Schema({
18 | username: String,
19 | password: String,
20 | });
21 |
22 | const UserSchema = new mongoose.Schema({
23 | username: String,
24 | password: String,
25 | purchasedCourses: [
26 | {
27 | type: mongoose.Schema.Types.ObjectId,
28 | ref: "Course",
29 | },
30 | ],
31 | });
32 |
33 | const CourseSchema = new mongoose.Schema({
34 | title: String,
35 | description: String,
36 | imageLink: String,
37 | price: Number,
38 | });
39 |
40 | const Admin = mongoose.model("Admin", AdminSchema);
41 | const User = mongoose.model("User", UserSchema);
42 | const Course = mongoose.model("Course", CourseSchema);
43 |
44 | module.exports = {
45 | Admin,
46 | User,
47 | Course,
48 | };
49 |
--------------------------------------------------------------------------------
/week-6/1-use-memo/src/components/Assignment3.jsx:
--------------------------------------------------------------------------------
1 | import React, { useState, useMemo } from "react";
2 | // You have been given a list of items you shopped from the grocery store
3 | // You need to calculate the total amount of money you spent
4 |
5 | export const Assignment3 = () => {
6 | const [items, setItems] = useState([
7 | { name: "Chocolates", value: 10 },
8 | { name: "Chips", value: 20 },
9 | { name: "Onion", value: 30 },
10 | { name: "Tomato", value: 30 },
11 | // Add more items as needed
12 | ]);
13 |
14 | // Your code starts here
15 | const total = useMemo(() => {
16 | let totalValue = 0;
17 | for (let i = 0; i < items.length; i++) {
18 | totalValue += items[i].value;
19 | }
20 | return totalValue;
21 | }, [items]);
22 | // Your code ends here
23 | return (
24 |
25 |
26 | {items.map((item, index) => (
27 |
28 | {item.name} - Price: ${item.value}
29 |
30 | ))}
31 |
32 |
Total Value: {total}
33 |
34 | );
35 | };
36 |
--------------------------------------------------------------------------------
/week-3/mongo-with-jwt-auth/db/index.js:
--------------------------------------------------------------------------------
1 | const mongoose = require("mongoose");
2 |
3 | mongoose
4 | .connect(
5 | "MONGO_URL",
6 | {
7 | useNewUrlParser: true,
8 | }
9 | )
10 | .then(() => {
11 | console.log("Connected to MongoDB");
12 | })
13 | .catch((e) => {
14 | console.log(e);
15 | });
16 |
17 | // Define schemas
18 | const AdminSchema = new mongoose.Schema({
19 | username: String,
20 | password: String,
21 | });
22 |
23 | const UserSchema = new mongoose.Schema({
24 | username: String,
25 | password: String,
26 | purchasedCourses: [
27 | {
28 | type: mongoose.Schema.Types.ObjectId,
29 | ref: "Course",
30 | },
31 | ],
32 | });
33 |
34 | const CourseSchema = new mongoose.Schema({
35 | title: String,
36 | description: String,
37 | imageLink: String,
38 | price: Number,
39 | });
40 |
41 | const Admin = mongoose.model("Admin", AdminSchema);
42 | const User = mongoose.model("User", UserSchema);
43 | const Course = mongoose.model("Course", CourseSchema);
44 |
45 | module.exports = {
46 | Admin,
47 | User,
48 | Course,
49 | };
50 |
--------------------------------------------------------------------------------
/week-13/blog-stack/frontend/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "frontend",
3 | "private": true,
4 | "version": "0.0.0",
5 | "type": "module",
6 | "scripts": {
7 | "dev": "vite",
8 | "build": "tsc && vite build",
9 | "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
10 | "preview": "vite preview"
11 | },
12 | "dependencies": {
13 | "@sai48/medium-validate2": "^1.0.0",
14 | "@types/axios": "^0.14.0",
15 | "react": "^18.2.0",
16 | "react-dom": "^18.2.0",
17 | "react-router-dom": "^6.22.3"
18 | },
19 | "devDependencies": {
20 | "@types/react": "^18.2.56",
21 | "@types/react-dom": "^18.2.19",
22 | "@typescript-eslint/eslint-plugin": "^7.0.2",
23 | "@typescript-eslint/parser": "^7.0.2",
24 | "@vitejs/plugin-react": "^4.2.1",
25 | "autoprefixer": "^10.4.18",
26 | "eslint": "^8.56.0",
27 | "eslint-plugin-react-hooks": "^4.6.0",
28 | "eslint-plugin-react-refresh": "^0.4.5",
29 | "postcss": "^8.4.35",
30 | "tailwindcss": "^3.4.1",
31 | "typescript": "^5.2.2",
32 | "vite": "^5.1.4"
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/week-2/async-js/easy/read_from_file.md:
--------------------------------------------------------------------------------
1 | ## Reading the contents of a file
2 |
3 | Write code to read contents of a file and print it to the console.
4 | You can use the fs library to as a black box, the goal is to understand async tasks.
5 | Try to do an expensive operation below the file read and see how it affects the output.
6 | Make the expensive operation more and more expensive and see how it affects the output.
7 |
8 | const fs = require('fs');
9 |
10 | // Read contents of a file
11 | fs.readFile('a.txt', 'utf8', (err, data) => {
12 | if (err) {
13 | console.error('Error reading the file:', err);
14 | return;
15 | }
16 |
17 | console.log('File Contents:', data);
18 |
19 | // Simulate an expensive operation (CPU-intensive task)
20 | // Example: Calculating Fibonacci series recursively
21 | const fibonacci = (num) => {
22 | if (num <= 1) {
23 | return num;
24 | }
25 | return fibonacci(num - 1) + fibonacci(num - 2);
26 | };
27 |
28 | const expensiveOperationResult = fibonacci(35); // Adjust the number for higher expenses
29 | console.log('Result of expensive operation:', expensiveOperationResult);
30 | });
31 |
--------------------------------------------------------------------------------
/week-4/full_stack_todo/frontend/src/App.jsx:
--------------------------------------------------------------------------------
1 | // import { useState } from "react";
2 | import { useEffect, useState } from "react";
3 | import CreateTodo from "./components/CreateTodo";
4 | import Todos from "./components/Todos";
5 |
6 | function App() {
7 | const [todos, setTodos] = useState([]);
8 |
9 | const handleUpdateTodoId = (id) => {
10 | // Here you can update the todo ID in the state
11 | // For simplicity, let's just log it
12 | console.log(`Todo with ID ${id} updated`);
13 | };
14 |
15 | useEffect(() => {
16 | fetch("http://localhost:3000/todos")
17 | .then(async function (res) {
18 | if (!res.ok) {
19 | throw new Error("Failed to fetch todos");
20 | }
21 | const json = await res.json();
22 | setTodos(json);
23 | })
24 | .catch((error) => {
25 | console.error("Error fetching todos:", error);
26 | });
27 | });
28 |
29 | return (
30 |
31 |
32 |
33 |
34 | );
35 | }
36 |
37 | export default App;
38 |
--------------------------------------------------------------------------------
/week-2/async-js/easy/write_from_file.md:
--------------------------------------------------------------------------------
1 | ## Write to a file
2 |
3 | Using the fs library again, try to write to the contents of a file.
4 | You can use the fs library to as a black box, the goal is to understand async tasks.
5 |
6 | const fs = require("fs");
7 |
8 | ---------------------------------------appendFile
9 |
10 | // Content to write to the file
11 | const content = "Hello, this is a test content to write to a file.\n";
12 |
13 | // Write content to a file asynchronously
14 | fs.appendFile("a.txt", content, "utf8", (err) => {
15 | if (err) {
16 | console.error("Error writing to the file:", err);
17 | return;
18 | }
19 | console.log("Content has been written to output.txt");
20 | });
21 |
22 | -------------------------------writeFile
23 |
24 | // Content to write to the file
25 | const content = "Hello, this is a test content to write to a file.\n";
26 |
27 | // Write content to a file asynchronously
28 | fs.writeFile("a.txt", content, "utf8", (err) => {
29 | if (err) {
30 | console.error("Error writing to the file:", err);
31 | return;
32 | }
33 | console.log("Content has been written to output.txt");
34 | });
35 |
--------------------------------------------------------------------------------
/week-16/Cookies.md:
--------------------------------------------------------------------------------
1 | # What are cookies
2 |
3 | ### Cookies in web development are small pieces of data sent from a website and stored on the user's computer by the user's web browser while the user is browsing. They are designed to be a reliable mechanism for websites to remember things (very similar to local storage)
4 |
5 | ## Session Management
6 |
7 | ## Personalization
8 |
9 | ## Tracking & Security
10 |
11 | # Why not local storage?
12 |
13 | ### Cookies and LocalStorage both provide ways to store data on the client-side, but they serve different purposes and have different characteristics.
14 |
15 | ## Cookies are send with every request to the website (by the browser) (you don’t have to explicitly add a header to the fetch call)
16 |
17 | ## Cookies can have an expiry attached to them
18 |
19 | ## Cookies can be be restricted to only https and to certain domains
20 |
21 | # Properties of cookies
22 |
23 | ## Types of cookies
24 |
25 | ### Persistent - Stay even if u close the window
26 |
27 | ### Session - Go away after the window closes
28 |
29 | ### Secure - Sent only over secure, encrypted connections (HTTPS).
30 |
--------------------------------------------------------------------------------
/week-3/jwt/index.js:
--------------------------------------------------------------------------------
1 | const jwt = require("jsonwebtoken");
2 | const jwtPassword = "secret";
3 | const zod = require("zod");
4 |
5 | const emailSchema = zod.string().email();
6 | const passwordSchema = zod.string().min(6);
7 |
8 | function signJwt(username, password) {
9 | const usernameResponse = emailSchema.safeParse(username); // validating using safeParse
10 | const passwordResponse = passwordSchema.safeParse(password);
11 | if (!usernameResponse.success || !passwordResponse.success) {
12 | return null;
13 | }
14 |
15 | const signature = jwt.sign(
16 | {
17 | username,
18 | },
19 | jwtPassword
20 | );
21 |
22 | return signature;
23 | }
24 |
25 | function verifyJwt(token) {
26 | let ans = true;
27 | try {
28 | jwt.verify(token, jwtPassword);
29 | } catch (e) {
30 | ans = false;
31 | }
32 | return ans;
33 | }
34 |
35 | function decodeJwt(token) {
36 | // true, false
37 | const decoded = jwt.decode(token);
38 | if (decoded) {
39 | return true;
40 | } else {
41 | return false;
42 | }
43 | }
44 |
45 | module.exports = {
46 | signJwt,
47 | verifyJwt,
48 | decodeJwt,
49 | jwtPassword,
50 | };
51 |
--------------------------------------------------------------------------------
/week-13/blog-stack/validateCommon/node_modules/zod/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Colin McDonnell
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/week-2/async-js/medium/clock.md:
--------------------------------------------------------------------------------
1 | Using `1-counter.md` or `2-counter.md` from the easy section, can you create a
2 | clock that shows you the current machine time?
3 |
4 | Can you make it so that it updates every second, and shows time in the following formats -
5 |
6 | - HH:MM::SS (Eg. 13:45:23)
7 |
8 | - HH:MM::SS AM/PM (Eg 01:45:23 PM)
9 |
10 | function updateClock() {
11 | const now = new Date();
12 |
13 | // Format for 24-hour clock (HH:MM:SS)
14 | const hours24 = ('0' + now.getHours()).slice(-2);
15 | const minutes = ('0' + now.getMinutes()).slice(-2);
16 | const seconds = ('0' + now.getSeconds()).slice(-2);
17 | const time24 = hours24 + ':' + minutes + ':' + seconds;
18 |
19 | // Format for 12-hour clock (HH:MM:SS AM/PM)
20 | const ampm = now.getHours() >= 12 ? 'PM' : 'AM';
21 | const hours12 = ('0' + ((now.getHours() % 12) || 12)).slice(-2);
22 | const time12 = hours12 + ':' + minutes + ':' + seconds + ' ' + ampm;
23 |
24 | // Log the time in both formats to the console
25 | console.log('24-hour format:', time24);
26 | console.log('12-hour format:', time12);
27 | }
28 |
29 | // Update the clock every second
30 | setInterval(updateClock, 1000);
31 |
32 | // Initial call to display the clock immediately
33 | updateClock();
34 |
--------------------------------------------------------------------------------
/week-1/basics/class.js:
--------------------------------------------------------------------------------
1 | class Animal {
2 | constructor(name, legCount) {
3 | this.name = name;
4 | this.legCount = legCount;
5 | }
6 |
7 | describe() {
8 | return `${this.name} has ${this.legCount} legs`;
9 | }
10 |
11 | sound(makeSound) {
12 | return `${this.name} makes the sound: ${makeSound}`;
13 | }
14 |
15 | move(moveType) {
16 | return `${this.name} moves by ${moveType}`;
17 | }
18 | }
19 |
20 | const dog = new Animal("Dog", 4);
21 | console.log(dog.describe());
22 | console.log(dog.sound("barking"));
23 | console.log(dog.move("running"));
24 |
25 | const cat = new Animal("Cat", 4);
26 | console.log(cat.describe());
27 | console.log(cat.sound("meowing"));
28 | console.log(cat.move("prowling"));
29 |
30 | const bird = new Animal("Bird", 2);
31 | console.log(bird.describe());
32 | console.log(bird.sound("chirping"));
33 | console.log(bird.move("flying"));
34 |
35 | const elephant = new Animal("Elephant", 4);
36 | console.log(elephant.describe());
37 | console.log(elephant.sound("trumpeting"));
38 | console.log(elephant.move("walking"));
39 |
40 | const snake = new Animal("Snake", 0);
41 | console.log(snake.describe());
42 | console.log(snake.sound("hissing"));
43 | console.log(snake.move("slithering"));
44 |
--------------------------------------------------------------------------------
/week-4/full_stack_todo/frontend/src/components/Todos.jsx:
--------------------------------------------------------------------------------
1 | // eslint-disable-next-line
2 | const Todos = ({ todos, onUpdateTodoId }) => {
3 | if (!todos) {
4 | return
43 | }
44 |
45 |
--------------------------------------------------------------------------------
/week-6/1-use-memo/src/components/Assignment2.jsx:
--------------------------------------------------------------------------------
1 | import React, { useEffect, useMemo, useState } from "react";
2 |
3 | // In this assignment, you will create a component that renders a large list of sentences and includes an input field for filtering these items.
4 | // The goal is to use useMemo to optimize the filtering process, ensuring the list is only re-calculated when necessary (e.g., when the filter criteria changes).
5 | // You will learn something new here, specifically how you have to pass more than one value in the dependency array
6 |
7 | const words = ["hi", "my", "name", "is", "for", "to", "random", "word"];
8 | const TOTAL_LINES = 1000;
9 | const ALL_WORDS = [];
10 | for (let i = 0; i < TOTAL_LINES; i++) {
11 | let sentence = "";
12 | for (let j = 0; j < words.length; j++) {
13 | sentence += words[Math.floor(words.length * Math.random())];
14 | sentence += " ";
15 | }
16 | ALL_WORDS.push(sentence);
17 | }
18 |
19 | export function Assignment2() {
20 | const [sentences, setSentences] = useState(ALL_WORDS);
21 | const [filter, setFilter] = useState("");
22 |
23 | const filteredSentences = useMemo(() => {
24 | return sentences.filter((x) => x.includes(filter));
25 | }, [sentences, filter]);
26 |
27 | return (
28 |
34 | Random catch phrase about the author's ability to grab the user's attention
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 | }
--------------------------------------------------------------------------------
/week-1/problems/hard/todo-list.js:
--------------------------------------------------------------------------------
1 | /*
2 | Implement a class `Todo` having below methods
3 | - add(todo): adds todo to list of todos
4 | - remove(indexOfTodo): remove todo from list of todos
5 | - update(index, updatedTodo): update todo at given index
6 | - getAll: returns all todos
7 | - get(indexOfTodo): returns todo at given index
8 | - clear: deletes all todos
9 |
10 | Once you've implemented the logic, test your code by running
11 | */
12 |
13 | class Todo {
14 | constructor() {
15 | this.todos = [];
16 | }
17 |
18 | add(todo) {
19 | this.todos.push(todo);
20 | }
21 |
22 | remove(indexOfTodo) {
23 | if (indexOfTodo >= 0 && indexOfTodo < this.todos.length) {
24 | this.todos.splice(indexOfTodo, 1);
25 | } else {
26 | throw new Error("Invalid index for removal.");
27 | }
28 | }
29 |
30 | update(index, updatedTodo) {
31 | if (index >= 0 && index < this.todos.length) {
32 | this.todos[index] = updatedTodo;
33 | } else {
34 | throw new Error("Invalid index for update.");
35 | }
36 | }
37 |
38 | getAll() {
39 | return this.todos;
40 | }
41 |
42 | get(indexOfTodo) {
43 | if (indexOfTodo >= 0 && indexOfTodo < this.todos.length) {
44 | return this.todos[indexOfTodo];
45 | } else {
46 | throw new Error("Invalid index to get todo.");
47 | }
48 | }
49 |
50 | clear() {
51 | this.todos = [];
52 | }
53 | }
54 |
55 | // Test your code
56 | const todoList = new Todo();
57 | todoList.add("Complete assignment");
58 | todoList.add("Buy groceries");
59 | todoList.add("Call mom");
60 |
61 | console.log("All Todos:", todoList.getAll());
62 |
63 | todoList.update(1, "Buy milk");
64 | console.log("Updated Todo at index 1:", todoList.get(1));
65 |
66 | todoList.remove(0);
67 | console.log("Todos after removal:", todoList.getAll());
68 |
69 | todoList.clear();
70 | console.log("Cleared Todos:", todoList.getAll());
71 |
72 | module.exports = Todo;
73 |
--------------------------------------------------------------------------------
/week-4/full_stack_todo/frontend/src/components/CreateTodo.jsx:
--------------------------------------------------------------------------------
1 | import { useState } from "react";
2 |
3 | function CreateTodo() {
4 | const [title, setTitle] = useState("");
5 | const [description, setDescription] = useState("");
6 |
7 | const handleTitleChange = (event) => {
8 | setTitle(event.target.value);
9 | };
10 |
11 | const handleDescriptionChange = (event) => {
12 | setDescription(event.target.value);
13 | };
14 |
15 | const handleAddTodo = () => {
16 | // Make sure title and description are not empty before sending the request
17 | if (!title.trim() || !description.trim()) {
18 | alert("Title and description are required");
19 | return;
20 | }
21 |
22 | fetch("http://localhost:3000/todos", {
23 | method: "POST",
24 | headers: {
25 | "Content-Type": "application/json",
26 | },
27 | body: JSON.stringify({ title, description }),
28 | })
29 | .then((response) => {
30 | if (!response.ok) {
31 | throw new Error("Failed to add todo");
32 | }
33 | return response.json();
34 | })
35 | .then((data) => {
36 | // Handle success response if needed
37 | console.log("Todo added successfully:", data);
38 | setTitle("");
39 | setDescription("");
40 | })
41 | .catch((error) => {
42 | console.error("Error adding todo:", error);
43 | });
44 | };
45 |
46 | return (
47 |
48 |
Create Todo
49 |
55 |
56 |
62 |
63 |
64 |
65 | );
66 | }
67 |
68 | export default CreateTodo;
69 |
--------------------------------------------------------------------------------
/week-0/basics/introduction.txt:
--------------------------------------------------------------------------------
1 | ------------------------------------------------------------------------------------------
2 | In this week will learn some things those are
3 |
4 | *Before get started learn about Browsers and IDE's is most imp
5 |
6 | Browsers:
7 | Browser is some sort of software which used to allow people to search something on computer, and get back with some sort of information with using HTML and CSS and JS files from server.
8 |
9 | IDE's:(Integrated development environment)
10 | IDE's are code playground, simply where people write or manupulate code.
11 |
12 | start off web development mostly frontend development which includes
13 | * HTML
14 | * CSS
15 |
16 |
17 | HTML => Hypertext Markup Langauge
18 |
19 | Which mainly used to create the structure of the webpage.
20 |
21 | Mostly with
22 | @tags
23 | @attributes
24 |
25 | Tags: We have to structure the HTML elements using tags in HTML
26 |
27 | Some most tags used:
28 |
29 |
30 |
31 |