// let score = 10;
// let newScore = 10 + score;
// typeof newScore;
// // coersion -> implicit (automatic) conversion
// // 100 + '100' => '100' + '100' => '100100'
let greeting = 'Hello World, Welcome to RST Forum.';
// 6.toUpperCase();
// iterpolation
let message = 'Hello World\nThis is on a new line.\nThank you.';
message = `Hello World
This is on a new line.
Thank you`;
// let age = 18;
// if (age >= 65) {
// console.log('Drink are free');
// } else if (age >= 21) {
// console.log('You can enter and drink');
// } else if (age >= 18) {
// console.log("You are allowed to enter but you can't drink");
// } else {
// console.log('Not allowed');
// }
// let age = 66;
// if (age > 18) {
// console.log('Entry Granted!');
// } else if (age >= 21) {
// console.log('Drinks Allowed');
// } else if (age >= 65) {
// console.log('Drinks FREE!');
// }
// if (age % 2 === 0) {
// console.log('Even age');
// } else {
// console.log('Odd age');
// }
// let password = 'helloworld';
// if (password.length > 6) {
// if (password.indexOf(' ') !== -1) {
// console.log('Password cannot contain spaces');
// } else {
// console.log('Valid password');
// }
// } else {
// console.log('Password is too short');
// }
let user = null;
if (user) {
console.log('Welcome home');
} else {
console.log('Please login first');
}
// let age = 18;
// if (age >= 18 && age < 21) {
// console.log("You are allowed to enter but you can't drink");
// } else if (age >= 21 && age < 65) {
// console.log('You can enter and drink');
// } else if (age >= 65) {
// console.log('Drink are free');
// } else {
// console.log('Not allowed');
// }
// let day = -1;
// if (day === 1) {
// console.log('Mon');
// } else if (day === 2) {
// console.log('Tue');
// } else if (day === 3) {
// console.log('Wed');
// } else if (day === 4) {
// console.log('Thu');
// } else if (day === 5) {
// console.log('Fri');
// } else if (day === 6) {
// console.log('Sat');
// } else if (day === 7) {
// console.log('Sun');
// } else {
// console.log('Invalid day code');
// }
// switch (day) {
// case 1:
// console.log('Mon');
// break;
// case 2:
// console.log('Tue');
// break;
// case 3:
// console.log('Wed');
// break;
// case 4:
// console.log('Thu');
// break;
// case 5:
// console.log('Fri');
// break;
// case 6:
// console.log('Sat');
// break;
// case 7:
// console.log('Sun');
// break;
// default:
// console.log('Invalid day code');
// }
// let age = 3;
// age >= 65
// ? console.log('Drink are free')
// : age >= 21
// ? console.log('Can drink')
// : age >= 18
// ? console.log('Can not drink')
// : console.log('Not allowed');
// let stat = 'online';
// let color = stat === 'online' ? 'green' : 'gray';
// console.log(color);
let cart = ['iPhone 12', 'Macbook Air', 'Apple watch'];
let deletedItem = cart.pop();
// const product1 = ['Apple iPhone', 'Apple', 'Some description...', 500, 100000];
// const product2 = {
// price: 100000,
// description: 'Some description...',
// inStock: 500,
// brand: 'Apple',
// imageUrl: 'https://....',
// name: 'Apple iPhone',
// 1: 'Hello',
// 'The cost': false,
// };
// product1[1];
// product2.brand;
// console.log(product2[1]);
// console.log(product2['brand']);
// console.log(product2['The cost']);
// const pallette = {
// red: '#eb4d4b',
// yellow: '#f9ca24',
// blue: '#30336b',
// };
// let color = 'red';
// console.log(pallette[color]);
// const product2 = {
// price: 100000,
// description: 'Some description...',
// inStock: 500,
// };
// product2.something = 'Hello';
// product2.brand = 'Apple';
// product2.inStock++;
// product2.price = 1000;
// console.log(product2);
// for (let i = 0; i < 10000000; i++) {
// console.log(`${i} - Hello World`);
// }
// for (let i = 100; i > 0; i -= 5) {
// console.log(`${i} - Hello World`);
// }
// const nums = [12, 34, 56, 34, 78, 54, 23, 12];
// for (let i = 0; i < nums.length; i++) {
// console.log(nums[i]);
// }
// const movies = [
// { movieName: 'Inception', rating: 3.8 },
// { movieName: 'Avengers', rating: 3.4 },
// { movieName: 'Iron Man', rating: 2.9 },
// ];
// for (let i = 0; i < movies.length; i++) {
// let movie = movies[i];
// console.log(`${movie.movieName} has a rating of ${movie.rating}`);
// }
// const word = 'Hello World';
// // for (let char = 0; char < word.length; char++) {
// // console.log(word[char]);
// // }
// let reversedString = '';
// for (let i = word.length - 1; i >= 0; i--) {
// reversedString += word[i];
// }
// console.log(reversedString);
// for (let i = 0; i < 5; i++) {
// console.log(i);
// for (let j = 0; j < 5; j++) {
// console.log(' ', j);
// }
// }
const gameBoard = [
[4, 64, 8, 4],
[128, 32, 4, 16],
[16, 4, 4, 32],
[2, 16, 16, 2],
];
let total = 0;
for (let i = 0; i < gameBoard.length; i++) {
for (let j = 0; j < gameBoard[i].length; j++) {
// console.log(gameBoard[i][j]);
total += gameBoard[i][j];
}
}
console.log(total);
// Task 1
const gameBoard2 = [
[
[
[1, 2, 3, 4, 5, 3, 1],
[1, 2, 3, 4],
[1, 2, 3, 4, 4, 5, 3],
[1, 2],
],
[1, 2, 3, 4],
[1, 2, 3, 4],
[1, 2, 3, 4],
],
[
[1, 2, 3, 4],
[1, 2, 3, 4],
[1, 2, 3, 4],
[1, 2, 3, 4],
],
];
// for (let i = 0; i < 10; i++) {
// console.log(i);
// }
// let i = 0;
// while (i < 10) {
// console.log(i);
// i++;
// }
// const target = Math.floor(Math.random() * 100) + 1;
// let guess = Math.floor(Math.random() * 100) + 1;
// while (guess !== target) {
// if (guess === 13) {
// break;
// }
// console.log(`Target: ${target}\nGuess: ${guess}`);
// guess = Math.floor(Math.random() * 100) + 1;
// }
// console.log(`You have the right number:\nTarget: ${target} | Guess: ${guess}`);
// const target = Math.floor(Math.random() * 100) + 1;
// let guess = Math.floor(Math.random() * 100) + 1;
// while (true) {
// console.log(`Target: ${target}\nGuess: ${guess}`);
// if (guess === target) {
// break;
// }
// guess = Math.floor(Math.random() * 100) + 1;
// }
// console.log(`You have the right number:\nTarget: ${target} | Guess: ${guess}`);
// const names = ['john', 'jane', 'jack', 'james', 'joe', 'jolly', 'johnny'];
// for (let i = 0; i < names.length; i++) {
// console.log(names[i]);
// }
// for (let name of names) {
// console.log(name);
// }
// // iteration
// let name = 'John Doe';
// for (let char of name) {
// console.log(char);
// }
// const nums = [
// [
// [1, 2, 3],
// [1, 2, 3],
// [1, 2, 3],
// ],
// [
// [1, 2, 3],
// [1, 2, 3],
// [1, 2, 3],
// ],
// [
// [1, 2, 3],
// [1, 2, 3],
// [1, 2, 3],
// ],
// ];
// for (let firstItems of nums) {
// for (let secondItems of firstItems) {
// for (let thirdItems of secondItems) {
// console.log(thirdItems);
// }
// }
// }
// const productPrices = {
// Apple: 80000,
// OnePlus: 50000,
// Samsung: 90000,
// };
// for (let key of Object.keys(productPrices)) {
// console.log(productPrices[key]);
// }
// for (let key in productPrices) {
// console.log(productPrices[key]);
// }
// for (let value of Object.values(productPrices)) {
// console.log(value);
// }
// const movieRating = {
// pursuitOfHappiness: 4.8,
// satya: 4.8,
// gangsOfWasepur: 4,
// robot: NaN,
// deshDrohi: Infinity,
// };
// for (let movie in movieRating) {
// console.log(`${movie} has a rating of ${movieRating[movie]}`);
// }
const nums = [
[
[1, 2, 3],
[1, 2, 3],
[1, 2, 3],
],
[
[1, 2, 3],
[1, 2, 3],
[1, 2, 3],
],
[
[1, 2, 3],
[1, 2, 3],
[1, 2, 30],
],
];
let total = 0;
for (let i = 0; i < nums.length; i++) {
for (let j = 0; j < nums[i].length; j++) {
for (let k = 0; k < nums[i][j].length; k++) {
total += nums[i][j][k];
}
}
}
console.log(total);
// function greet() {
// console.log('Hello');
// console.log('World');
// }
// greet();
// for (let i = 0; i < 50; i++) {
// greet();
// }
function rollDie() {
let roll = Math.floor(Math.random() * 6) + 1;
console.log(`Rolled: ${roll}`);
}
// function throwDice() {
// rollDie();
// rollDie();
// rollDie();
// }
// throwDice();
// function greet(name) {
// console.log(`Hello, ${name}`);
// }
// greet('John');
// greet('Jane');
// function throwDice(times) {
// for (let i = 0; i < times; i++) {
// rollDie();
// }
// }
// throwDice(3);
// function greet(name, message) {
// console.log(`${message}, ${name}`);
// }
// greet('John');
// function add(a, b) {
// console.log('Hello world');
// return a + b;
// }
// let result = add(10, 20);
// console.log(result);
// console.log(add(100, 100));
// function isNumber(val) {
// if (typeof val === 'number') {
// return true;
// }
// return false;
// }
// console.log(isNumber('hello'));
// console.log(isNumber(true));
// let firstName = 'Jane Smith';
// function greet() {
// let firstName = 'John Doe';
// console.log(firstName);
// }
// console.log(firstName);
// greet();
// if (true) {
// var firstName = 'John';
// console.log(firstName);
// }
// console.log(firstName);
// for (var i = 0; i < 10; i++) {
// console.log(i);
// }
// console.log(i);
// console.log(firstName);
// var firstName = 'John';
// function greet() {
// var firstName = 'john';
// console.log(firstName);
// }
// // if (true) {
// // let firstName = 'john';
// // console.log(firstName);
// // }
// console.log(firstName);
// // greet();
// function outer() {
// function inner() {
// let movie = 'John Wick';
// console.log(movie);
// }
// console.log(movie);
// inner();
// }
// outer();
// function square(num) {
// return num * num;
// }
// const cube = function (num) {
// return num * num * num;
// };
// console.log(square(10));
// console.log(cube(10));
const arr = [
function (a, b) {
return a + b;
},
function (a, b) {
return a - b;
},
function (a, b) {
return a * b;
},
function (a, b) {
return a / b;
},
];
const math = {
add: function (a, b) {
return a + b;
},
sub: function (a, b) {
return a - b;
},
mul: function (a, b) {
return a * b;
},
div: function (a, b) {
return a / b;
},
};
console.log(math.add(10, 5));
// console.log(arr[2](10, 5));
// const arr2 = [1, 2, 3, 4];
// 1
// function add(num1, num2) {
// return num1 + num2;
// }
// const sub = function (num1, num2) {
// return num1 - num2;
// };
// const math = {
// add: add,
// sub: sub,
// mul: function (num1, num2) {
// return num1 * num2;
// },
// PI: 3.1415,
// };
// console.log(math.PI);
// console.log(add(10, 5));
// console.error('Hello World');
// const helloworld = sub;
// console.log(sub(10, 5));
// console.log(helloworld(10, 2));
// function math(a, b, fn) {
// return fn(a, b);
// }
// function add(num1, num2) {
// return num1 + num2;
// }
// let result = math(10, 5, add);
// let result = math(10, 2, function (num1, num2) {
// return num1 * num2;
// });
// console.log(result);
// function greet(name) {
// function mood() {
// const moods = ['Hi', 'Hello', 'Get lost', 'F off', '---'];
// const random = Math.floor(Math.random() * moods.length);
// return moods[random];
// }
// return `${mood()}, ${name}`;
// }
// console.log(greet('John'));
// function repeat(func, num) {
// for (let i = 0; i < num; i++) {
// func();
// }
// }
// function sayHello() {
// console.log('Hello World!');
// }
// function sayGoodbye() {
// console.log('Bye World!');
// }
// repeat(sayHello, 10);
// repeat(sayGoodbye, 5);
// // function => keyword
// // add => function's name
// // (a, b) => parameters (one or more)
// // {} => code block
// // return => return/replace/give back whatever is on it's right
// // add(10, 5) => this expression will become 15
// function add(a, b) {
// return a + b;
// }
// // LEXICAL SCOPING
// function raiseby(num) {
// const res = function (x) {
// return x ** num;
// };
// return res;
// }
// const cube = raiseby(3);
// const square = raiseby(2);
// const tesseract = raiseby(4);
// console.log(cube(2));
// console.log(square(2));
// function isBetween(x, y) {
// return function (num) {
// return num >= x && num < y;
// };
// }
// const isMinor = isBetween(1, 18);
// const isUnderAge = isBetween(18, 21);
// const isLegalAge = isBetween(21, 65);
// const isOverAge = isBetween(65, 100);
// console.log(isUnderAge(40));
// console.log(isOverAge(88));
function generateEvens() {
const evens = [];
for (let i = 1; i < 50; i++) {
if (i % 2 === 0) {
evens.push(i);
}
}
return evens;
}
console.log(generateEvens());
// rahul@rstforum.co.in
// function math(a, b, fn) {
// return fn(a, b);
// }
// function add(a, b) {
// return a + b;
// }
// const result = math(10, 5, add);
// console.log(result);
// setTimeout(function () {
// console.log('Hello World');
// }, 5000);
// function logHello() {
// console.log('Hello World');
// }
// setTimeout(logHello, 1000);
// console.log("Hello World")
// let name = 'John';
// // Impure function - side effects
// // function cap() {
// // name = name.toUpperCase();
// // }
// function cap(name) {
// return name.toUpperCase();
// }
// name = cap(name);
// console.log(name);
greet('John');
function greet(person) {
console.log(`HELLO, ${person}`);
}
// const greet = function (person) {
// console.log(`HELLO, ${person}`);
// }
// /**
// * @desc "Function that takes 3 params and return it's calc"
// * @param a: number
// * @param b: number
// * @param fn: function that
// */
// function math(a, b, fn) {
// return fn(a, b);
// }
// function add(a, b) {
// return a + b;
// }
// math(10, 5, add);
// const nums = [1, 2, 3, 4, 5, 6, 7];
// // for (let num of nums) {
// // console.log(num);
// // }
// nums.forEach(function (num) {
// if (num % 2 === 0) {
// console.log(num);
// }
// });
// const movies = [
// {
// title: 'Avengers',
// rating: 4.1,
// },
// {
// title: 'Dr. Strange',
// rating: 3.9,
// },
// {
// title: 'Tenet',
// rating: 4.3,
// },
// {
// title: 'Joker',
// rating: 4.7,
// },
// ];
// movies.forEach(function (movie, i) {
// console.log(`${i} - ${movie.title} has a rating of ${movie.rating}`);
// });
// const names = ['john', 'jack', 'jane', 'james'];
// const upperNames = [];
// for (let name of names) {
// upperNames.push(name.toUpperCase());
// }
// console.log(upperNames);
// const upperCasedNames = names.map(function (name) {
// return name.toUpperCase();
// });
// console.log(upperCasedNames);
// const movies = [
// {
// title: 'Avengers',
// rating: 4.1,
// },
// {
// title: 'Dr. Strange',
// rating: 3.9,
// },
// {
// title: 'Tenet',
// rating: 4.3,
// },
// {
// title: 'Joker',
// rating: 4.7,
// },
// ];
// const movieNames = movies.map(function (movie) {
// return movie.title;
// });
// console.log(movieNames);
// const nums = [2, 3, 4, 7, 6, 8, 13, 10, 19, 12, 14, 22, 21, 16];
// // const doubles = nums.map(function (num) {
// // return num * 2; // we have to return a value
// // });
// // console.log(doubles);
// const numDetails = nums.map(function (num) {
// return {
// number: num,
// isEven: num % 2 === 0,
// };
// });
// console.log(numDetails);
// const nums = [2, 3, 4, 7, 6, 8, 13, 10, 19, 12, 14, 22, 21, 16];
// const doubles = nums.map(function (num) {
// return num * 2;
// });
// const doubles = nums.map((num) => {
// return num * 2;
// });
// const doubles = nums.map((num) => (
// num * 2
// ));
// const doubles = nums.map((num) => (num * 2));
// const doubles = nums.map((num) => num * 2);
// const doubles = nums.map((n, i) => n * 2);
// console.log(doubles);
// const add = function (a, b) {
// return a + b;
// }
// const add2 = (a, b) => {
// console.log("Hello World")
// return a + b
// };
// let movies = ['The Terminator', 'The Avengers', 'Jurassic Park', 'Titanic']
// let searchResult = movies.find((movie) => movie.includes("Av"))
// console.log(searchResult)
// const movies = [
// {
// title: 'Avengers',
// rating: 4.1,
// },
// {
// title: 'Dr. Strange',
// rating: 3.9,
// },
// {
// title: 'Tenet',
// rating: 3.9,
// },
// {
// title: 'Joker',
// rating: 4.7,
// },
// ];
// const searchResult = movies.find((movie) => movie.rating < 2);
// console.log(searchResult);
// const books = [
// {
// title: 'The Shining',
// author: 'Stephen King',
// rating: 4.1,
// },
// {
// title: 'Sacred Games',
// author: 'Vikram Chandra',
// rating: 4.5,
// },
// {
// title: '1984',
// author: 'George Orwell',
// rating: 4.9,
// },
// {
// title: 'The Alchemist',
// author: 'Paulo Coelho',
// rating: 3.5,
// },
// {
// title: 'The Great Gatsby',
// author: 'F. Scott Fitzgerald',
// rating: 3.8,
// },
// ];
// const searchRes1 = books.filter((book) => book.rating < 2);
// // const searchRes2 = books.find((book) => book.author === 'George Orwell');
// console.log(searchRes1);
// // console.log(searchRes2);
// const names = ['jack', 'james', 'john', 'jane', 'josh', 'jrad'];
// const res = names.some((name) => name[0] === 'b');
// console.log(res);
// const prices = [500.4, 211, 23, 5, 4, 22.2, -23.2, 9233];
// const prices = [1, 4, -2, 5, 1, 2];
// prices.sort((a, b) => b - a);
// console.log(prices);
const nums = [2, 3, 4, 7, 6, 8, 13, 10, 19, 12, 14, 22, 21, 16];
const res = nums.reduce((acc, currVal) => acc + currVal, 100);
// const res = nums.reduce((acc, currVal) => {
// if (currVal > acc) {
// return currVal;
// }
// return acc;
// });
console.log(res);
// acc - 9
// currVal - 7
// const multiply = (a = 1, b = 1) => {
// // if (typeof a === 'undefined') {
// // a = 1;
// // }
// // if (typeof b === 'undefined') {
// // b = 1;
// // }
// return a * b;
// };
// console.log(multiply(10));
// function printVals(a, b, c) {
// console.log(a);
// console.log(b);
// console.log(c);
// }
// const names = ['john', 'jane', 'jack'];
// printVals(...'john');
// function add(...data) {
// return data.reduce((acc, currVal) => acc + currVal);
// }
// console.log(add(10, 2, 3, 32, 3, 3));
// const users = ['john', 'jane', 'jack'];
// // const admin = users[0];
// // const moderator = users[1];
// // const user = users[2];
// const [admin, ...others] = users;
// console.log(admin, others);
// const user = {
// firstName: 'John',
// lastName: 'Doe',
// email: 'john.doe@gmail.com',
// phone: 99982234567,
// };
// const { firstName, lastName, email: emailAddress, phone } = user;
// // const firstName = user.firstName;
// // const lastName = user.lastName;
// console.log(firstName, lastName, emailAddress, phone);
// function profile({ name, age, profession }) {
// console.log(`Name: ${name}`);
// console.log(`Age: ${age}`);
// console.log(`Profession: ${profession}`);
// }
// profile({ name: 'Jane Doe', age: 20, profession: 'Programmer' });
// const movieReviews = [4.5, 5.0, 3.2, 2.1, 4.7, 3.8, 3.1, 3.9, 4.4];
// const highest = Math.max(...movieReviews);
// const lowest = Math.min(...movieReviews);
// // let total = 0;
// // movieReviews.forEach((rating) => (total += rating));
// // const average = total / movieReviews.length;
// // const info = { highest, lowest, average };
// // console.log(info);
// const username = 'janedoe';
// const role = 'admin';
// const user1 = { [role.toUpperCase()]: username };
// console.log(user1);
// const addProperty = (obj, k, v) => {
// return { ...obj, [k]: v };
// };
// console.log(
// addProperty({ name: 'Jane Doe', age: 20 }, 'profession', 'Programmer')
// );
// const math = {
// multiply(x, y) {
// return x * y;
// },
// divide(x, y) {
// return x / y;
// },
// subtract(x) {
// return x - x;
// },
// };
// console.log(math.multiply(10, 2));
function greet() {
console.log(`${this.name} is ${this.age} years old`);
}
const user1 = {
name: 'John',
age: 20,
greet,
};
const user2 = {
name: 'Jane',
age: 22,
greet,
};
user1.greet();
user2.greet();
// window.nameste();
// user.greet();
// console.log('Hello from scratchpad 11');
// console.log(this);
// window object
// global object
function addTheseNumbers(a, b) {
console.log(this);
return a + b;
}
const myMathObject = {
hello: 'world',
add(a, b) {
console.log(this);
return a + b;
},
sub(a, b) {
return a - b;
},
};
// addTheseNumbers(10, 5);
// myMathObject.add(10, 5);
// console.log(window.addTheseNumbers(10, 5));
// myMathObject.add(10, 5);
// myMathObject.sub(10, 5);
// console.log(this); // current execution scope
// function greet() {
// console.log(
// `My name is ${this.firstName} ${this.lastName} and I am ${this.age} years old`
// );
// }
// const user1 = {
// firstName: 'John',
// lastName: 'Doe',
// age: 20,
// greet,
// };
// const user2 = {
// firstName: 'Jane',
// lastName: 'Doe',
// age: 22,
// greet,
// };
// user1.greet();
// user2.greet();
// let aaaaaaaaaa = 'HELLO WORLD';
// console.log(this);
// const user = {
// firstName: 'John',
// lastName: 'Doe',
// role: 'admin',
// fullName() {
// const { firstName, lastName, role } = this; // Object Destructuring
// console.log(`${firstName} ${lastName} is an ${role}`);
// },
// };
// user.fullName();
// const user = {
// firstName: 'John',
// lastName: 'Doe',
// role: 'admin',
// fullName() {
// return `${this.firstName} ${this.lastName} is an ${this.role}`;
// },
// logDetails() {
// console.log(`${this.fullName()} and is cool!`);
// },
// };
// user.logDetails();
// const logDetails = user.logDetails;
// logDetails();
// // this -> window
// const hellos = {
// messages: [
// 'hello world',
// 'hello universe',
// 'hello darkness',
// 'hello hello',
// 'heylo',
// ],
// pickMsg() {
// const index = Math.floor(Math.random() * hellos.messages.length);
// return this.messages[index];
// },
// start() {
// //this -> hellos
// setInterval(() => {
// console.log(hellos.pickMsg());
// }, 1000);
// },
// };
// hellos.start();
// // this => window
// const myMathObj = {
// num1: 1,
// num2: 2,
// add: function () {
// console.log(myMathObj.num1 + myMathObj.num2);
// },
// add2: () => {
// console.log(this.num1 + this.num2);
// },
// };
// // myMathObj.add();
// myMathObj.add2();
// const para = document.getElementById('para');
// const h3 = document.getElementById('impTitle');
// // console.dir(para);
// // console.dir(h3);
// const lis = document.getElementsByTagName('li');
// console.dir(lis[2]);
// for (let li of lis) {
// console.log(li.innerText);
// }
// const specials = document.getElementsByClassName('special')[0];
// console.dir(specials);
// const para = document.querySelector('#para');
// const specials = document.querySelectorAll('.special');
// const lis = document.querySelectorAll('[src]');
// console.dir(para);
// console.dir(specials);
// console.dir(lis);
// const para = document.querySelector('p');
// // console.log(para.innerText);
// para.innerText = 'Hello World';
// const ul = document.querySelector('ul');
// ul.innerText = 'Hello LISTT';
// console.dir(ul);
// const p = document.querySelector('.something');
// const p2 = document.querySelector('p');
// console.log(p.innerHTML);
// p2.innerHTML = '<strong>Hello</strong> World.';
// p2.innerHTML += '<br /><em>Hello Again</em>';
// const inp = document.querySelector('input');
const check = document.querySelector('#check');
// const a = document.querySelector('a');
// const p = document.querySelector('p');
// // console.log(inp.value);
// inp.value = 'Some information';
// check.checked = true;
// a.href = 'https://u5b.f44.myftpupload.com';
// p.id = 'someID';
// const range = document.querySelector('.range');
// console.log(range.getAttribute('href'));
// range.setAttribute('min', '-500');
// check.setAttribute('type', 'color');
// const ul = document.querySelector('ul');
// const lis = document.querySelectorAll('li');
// const li = lis[3];
// // console.log(li.parentElement.parentElement.parentElement);
// // console.log(ul.children);
// console.log(li.nextElementSibling.nextElementSibling);
// const lis = document.querySelectorAll('li');
// for (let li of lis) {
// li.innerText = 'Hello world';
// }
// const heading = document.querySelector('h1');
// console.log(heading.style);
// heading.style.color = 'red';
// heading.style.textDecoration = 'underline';
// const colors = ['red', 'purple', 'green', 'maroon', 'teal'];
// const lis = document.querySelectorAll('li');
// // for (let i = 0; i < lis.length; i++) {
// // lis[i].style.color = colors[i];
// // }
// for (let li of lis) {
// li.style.color = colors[Math.floor(Math.random() * colors.length)];
// li.style.fontWeight = 'bold';
// }
// const h1 = document.querySelector('h1');
// console.dir(h1.innerText);
// h1.style.color = 'green';
// console.log(h1.style.color);
// const h1Styles = getComputedStyle(h1);
// console.log(h1Styles.color);
// console.log(h1Styles.fontSize);
// h1.style.color = 'blue';
// h1.style.textDecoration = 'underline';
// h1.style.fontSize = '3rem';
// h1.style.fontWeight = '500';
// h1.setAttribute('class', 'todo heading');
// h1.setAttribute('class', 'heading');
// console.log(h1.classList);
// // h1.setAttribute('class', 'todo');
// // h1.classList.add('todo');
// // h1.classList.remove('todo');
// h1.classList.toggle('todo');
// const h2 = document.createElement('h2');
// h2.innerText = 'Some new title';
// h2.style.fontSize = '2.2rem';
// const p = document.createElement('p');
// p.innerText =
// 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Harum tempore eveniet magnam obcaecati, earum reprehenderit ipsa ea deserunt autem vitae';
// const div = document.createElement('div');
// div.appendChild(h2);
// div.appendChild(p);
// const container = document.querySelector('.container');
// container.appendChild(div);
// const list = document.querySelector('.list');
// const lis = list.querySelectorAll('li');
// // console.log(lis);
// const special = list.querySelector('.special');
// const newLi = document.createElement('li');
// newLi.innerText = 'Some new information';
// newLi.style.color = 'red';
// list.insertBefore(newLi, special);
// const newpara = document.querySelector('.newpara');
// const b = document.createElement('b');
// b.innerText = 'HELLO WORLD';
// const i = document.createElement('i');
// i.innerText = 'GOODBYE GALAXY';
// // newpara.insertAdjacentElement('afterend', b);
// newpara.prepend(b, i);
// const h1 = document.querySelector('h1');
// h1.remove();
// const btn = document.querySelector('button');
// btn.onclick = function () {
// console.log('Hello World');
// };
// btn.onclick = function () {
// console.log('Goodbye World');
// };
// const container = document.querySelector('.container');
// btn.addEventListener('click', function () {
// console.log('Hello World');
// const p = document.createElement('p');
// p.innerText = 'Hello World';
// p.addEventListener('mouseenter', function () {
// // p.remove();
// p.style.color = 'red';
// p.style.fontWeight = 'bold';
// });
// p.addEventListener('mouseleave', function () {
// // p.remove();
// p.style.color = 'black';
// p.style.fontWeight = 'normal';
// });
// container.append(p);
// });
// btn.addEventListener('click', function () {
// console.log('Goodbye World');
// });
// const btn = document.querySelector('button');
// console.log('TEST');
// btn.addEventListener('mouseover', function () {
// const height = Math.floor(Math.random() * window.innerHeight);
// const width = Math.floor(Math.random() * window.innerWidth);
// btn.style.top = `${height}px`;
// btn.style.left = `${width}px`;
// });
// btn.addEventListener('click', function () {
// btn.innerText = 'You Won!';
// document.body.style.backgroundColor = 'green';
// });
// const colors = [
// 'red',
// 'orange',
// 'yellow',
// 'green',
// 'blue',
// 'purple',
// 'indigo',
// 'violet',
// ];
// const container = document.querySelector('#boxes'); // Select the container
// const p = document.querySelector('p');
// for (let color of colors) {
// const box = document.createElement('div'); // Create a square box
// box.style.backgroundColor = color; // Style the box
// box.classList.add('box'); // Add a class
// container.append(box); // Append box to container
// // Add event listener to the box
// box.addEventListener('click', function () {
// // console.log('Box clicked!')
// console.log(box.style.backgroundColor);
// p.innerText = box.style.backgroundColor;
// });
// }
const btn = document.querySelector('button');
btn.addEventListener('click', function (event) {
console.log(event);
});
const input = document.querySelector('input');
const p = document.querySelector('p');
input.addEventListener('keypress', function (event) {
p.innerText = event.target.value;
});
// const multiply = (x, y) => x * y;
// const square = (x) => multiply(x, x);
// const rightTriangle = (a, b, c) => {
// return square(a) + square(b) === square(x);
// };
// rightTriangle(3, 4, 5);
// console.log('First function call');
// alert('This is the second function call');
// console.log('Third function call');
// console.log('First function call');
// setTimeout(function () {
// console.log('Second function call');
// }, 1000);
// console.log('Third function call');
// const btn = document.querySelector('button');
// setTimeout(() => {
// btn.style.transform = `translateX(100px)`;
// setTimeout(() => {
// btn.style.transform = `translateX(200px)`;
// setTimeout(() => {
// btn.style.transform = `translateX(300px)`;
// setTimeout(() => {
// btn.style.transform = `translateX(400px)`;
// setTimeout(() => {
// btn.style.transform = `translateX(500px)`;
// }, 1000);
// }, 1000);
// }, 1000);
// }, 1000);
// }, 1000);
const willGetAPlayStation = new Promise((resolve, reject) => {
setTimeout(() => {
if (Math.random() > 0.5) {
resolve();
} else {
reject();
}
}, 1000);
});
console.log(willGetAPlayStation);
willGetAPlayStation
.then(() => {
console.log('Thank you!');
})
.catch(() => {
console.log('Screw you!');
});
// const willGetAPlaystation = new Promise((resolve, reject) => {
// const randomNum = Math.random();
// if (randomNum > 0.5) {
// resolve();
// } else {
// reject();
// }
// });
// willGetAPlaystation
// .then(() => {
// console.log('Promise was resolved');
// })
// .catch(() => {
// console.error('Promise was rejected');
// });
// const makePlayStationPromise = () => {
// return new Promise((resolve, reject) => {
// setTimeout(() => {
// const randomNum = Math.random();
// if (randomNum > 0.5) {
// resolve();
// } else {
// reject();
// }
// }, 4000);
// });
// };
// makePlayStationPromise()
// .then(() => {
// console.log('Resolved');
// })
// .catch(() => {
// console.log('Rejected');
// });
// const makePlayStationPromise = () => {
// return new Promise((resolve, reject) => {
// setTimeout(() => {
// const randomNum = Math.random();
// if (randomNum > 0.5) {
// resolve('Hello');
// } else {
// reject('World');
// }
// }, 1000);
// });
// };
// makePlayStationPromise()
// .then((data) => {
// console.log(data);
// })
// .catch((err) => {
// console.error(err);
// });
// const fakeRequest = (url) => {
// return new Promise((resolve, reject) => {
// setTimeout(() => {
// const pages = {
// '/users': [
// { id: 1, username: 'john' },
// { id: 2, username: 'jane' },
// ],
// '/about': 'This is the about page',
// };
// const data = pages[url];
// if (data) {
// resolve({ status: 200, data });
// } else {
// reject({ status: 404 });
// }
// }, 2000);
// });
// };
// fakeRequest('/jkasnd')
// .then((data) => {
// console.log(data);
// })
// .catch((err) => console.log(err));
const fakeRequest = (url) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
const pages = {
'/users': [
{ id: 1, username: 'john' },
{ id: 2, username: 'jane' },
],
'/users/1': {
id: 1,
username: 'johndoe',
topPostId: 53231,
city: 'mumbai',
},
'/users/5': {
id: 1,
username: 'janedoe',
topPostId: 32443,
city: 'pune',
},
'/posts/53231': {
id: 1,
title: 'Really amazing post',
slug: 'really-amazing-post',
},
};
const data = pages[url];
if (data) {
resolve({ status: 200, data });
} else {
reject({ status: 404 });
}
}, 1000);
});
};
// { status: 200, data: [
// { id: 1, username: 'john' },
// { id: 2, username: 'jane' },
// ] }
// fakeRequest('/users').then((response) => {
// const userId = response.data[0].id;
// fakeRequest(`/users/${userId}`).then((response) => {
// const postId = response.data.topPostId;
// fakeRequest(`/posts/${postId}`).then((response) => {
// console.log(response.data);
// });
// });
// });
fakeRequest('/users')
.then((response) => {
const userId = response.data[0].id;
return fakeRequest(`/users/${userId}`);
})
.then((response) => {
const postId = response.data.topPostId;
return fakeRequest(`/posts/${postId}`);
})
.then((response) => {
console.log(response.data);
})
.catch((err) => console.log(err));
2. Chakra UI Installation and Setup
3. Create Header and Footer components
4. Create HomeScreen product listings
5. Install and Implement React Router
6. Design and build the ProductScreen component.
Setting up the backend
Fetching data from our backend using React
9. More backend setup
10. Setup environment variables
11. Convert imports to ES Modules
12. Install and setup MongoDB
13. Connect to the database
14. Improve console log messages.
15. Create database models for data
16. Prepare sample data for the backend data seeding
17. Create database seeder for quick sample data generation (optional)
18. Fetching products from the database
19. Do Postman setup to work with our API _(optional)_Custom error handling. Run the following in the root folder.
20. Custom error handling. Run the following in the root folder.
21. Introduction to Redux
22. Create our first reducer
23. Getting Redux State in the Home Screen
24. Create Message and Loader components.
25. Single product details screen Reducer and Action
26. Cart and Quantity
27. Cart Screen and Route
28. Cart Functionality
29. Completing CartScreen.js and creating ‘add to cart’ functionality
30. Clean up the backend routes by extracting their logic into controllers
31. User Authentication Endpoints (Backend Routes)
32. Using Json Web Tokens (JWT)
33. Creating custom Authentication Middleware to accessprotected routes.
34. User registration
35. User Login Reducer and Action
36. User Login Screen
37. Implement all the Login – Redux functionality in the LoginScreen component.
38. Header modification to show User and User Logout feature
39. User Register, Constants, Reducer, Action and Screen.
40. Update User Profile endpoint in the backend
41. User Profile Screen and Getting User Details
42. Add Update User Profile functionality
43. Shipping Screen and Save Address
44. Checkout Steps Component
45. PaymentScreen – where users can choose the payment method
46. Place Order Screen
47. Backend: Order controller and endpoint (route)
48. Create Order
49. Get Order By ID (Backend Endpoint)
50. Create the order details reducer and action (frontend)
51. Create the Order Screen component
52. Backend endpoint for updating an order to paid
53. Order pay reducer and action
54. Adding PayPal Payments
55. Show Orders on Profile Page
56. Clear state on logout
57. Admin Middleware and Getting Users Endpoint
58. Admin User List – Frontend
59. Admin Screen page security
60. Delete User Functionality (for Admins)
61. Backend endpoints for getting and updating user by it’s ID
62. User Edit screen and User Details screen components
63. Update user functionality
64. Admin – Product List
65. Admin – Delete Products
66. Create and Update Product Backend Endpoints
67. Admin – Create Product Screen
68. Product Edit Screen
69. Admin – Update Product Functionality
70. Image Upload Configuration and Endpoint
71. Upload images from the frontend
72. Admin – Order List
73. Admin – Mark order as delivered
74. Create Review Endpoint
75. Create Review Endpoint
76. Adding product reviews on the frontend