// let greeting = 'Hello World, Welcome to RST Forum.';
// greeting.toLowerCase().indexOf('world');
// let message = 'Hello World\nThis is another line\nOne more line';
// message = `Hello World
// This is another line
// And this is another`;
// let score = 1000;
// if (score > 100) {
// console.log('Pretty decent score');
// }
let age = 33;
if (age > 65) {
console.log('Drinks are free');
} else if (age >= 21) {
console.log('Drink are allowed');
} else if (age >= 18) {
console.log("You can enter but you can't drink");
} else {
console.log("You aren't allowed");
}
// let age = 33;
// if (age > 18) {
// console.log('Entry Granted!');
// } else if (age >= 21) {
// console.log('Drinks Allowed');
// } else if (age >= 65) {
// console.log('Drinks FREE!');
// }
let password = 'hel';
if (password.length > 6) {
if (password.search(' ') === -1) {
console.log('Good password');
} else {
console.log("Bad password. You can't have spaces");
}
} else {
console.log('Password is too short');
}
// let loggedInUser = 'john';
// if (loggedInUser) {
// console.log('Access Granted');
// } else {
// console.log('Access Denied');
// }
// let age = 33;
// if (age >= 18 && age < 21) {
// console.log('You are allowed to enter but not drink');
// } else if (age >= 21 && age < 65) {
// console.log('You are allowed to do anything');
// } else if (age >= 65) {
// console.log('Free drinks');
// } else {
// console.log('Not allowed');
// }
// if (day === 1) {
// console.log('Mon');
// } else if (day === 2) {
// console.log('Tue');
// }
// let day = 22;
// 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');
// }
// let statusMessage = 'offline';
// if (statusMessage === 'offline') {
// console.log('Red');
// } else {
// console.log('Green');
// }
// statusMessage === 'online' ? console.log('Red') : console.log('Green');
// let color = statusMessage === 'offline' ? 'red' : 'green';
// console.log(color);
// let age = 33;
// age >= 18 && age < 21
// ? console.log("Can enter, don't drink")
// : age >= 21 && age < 65
// ? console.log('You can drink')
// : age > 65
// ? console.log('Free drinks')
// : console.log('not allowed');
// let status = 'online';
// // let color = status === 'online' ? 'green' : 'red';
// let color;
// if (status === 'online') {
// color = 'green';
// } else {
// color = 'red';
// }
// function hello() {
// console.log('asdas');
// }
// console.log(hello);
// let colors = ['red', 'orange', 'yellow', 'green'];
// console.log(colors[colors.length - 1]);
// const products = [
// [1, 'iPhone 13', 'Apple', 'Some description....', 500, 100000, true],
// [2, 'iPhone 13', 'Apple', 'Some description....', 100000, 500, true],
// [3, 'iPhone 13', 'Apple', 'Some description....', 100000, 500, true],
// ];
// const iPhone = [
// 1,
// 'iPhone 13',
// 'Apple',
// 'Some description....',
// 100000,
// 500,
// true,
// ];
// console.log(iPhone[1]);
// // Array
// const product = [
// 1,
// 'iPhone 13',
// 'Apple',
// 'Some description....',
// 100000,
// 500,
// true,
// ];
// // Object
// const product2 = {
// srNo: 1,
// price: 100000,
// brand: 'Apple',
// inStock: 500,
// description: 'Some description....',
// name: 'iPhone 13',
// exchangeAvailable: true,
// };
// console.log(product[1]);
// console.log(product2.name);
// const products = [
// {
// srNo: 1,
// price: 100000,
// brand: 'Apple',
// inStock: 500,
// description: 'Some description....',
// name: 'iPhone 13',
// exchangeAvailable: true,
// },
// {
// srNo: 2,
// price: 100000,
// brand: 'Apple',
// inStock: 500,
// description: 'Some description....',
// name: 'iPhone 13',
// exchangeAvailable: true,
// },
// ];
// const product = {
// srNo: 1,
// price: 100000,
// brand: 'Apple',
// inStock: 500,
// description: 'Some description....',
// name: 'iPhone 13',
// exchangeAvailable: true,
// 1: true,
// 'some information': 100,
// };
// console.log(product.srNo);
// console.log(product.brand);
// console.log(product[1]);
// console.log(product['some information']);
// const arr1 = [1, 2, 3];
// const arr1 = { 0: 1, 1: 2, 2: 3, length: 3 };
// console.log(arr1[2]);
// const song = {
// name: 'Song Name',
// length: 3.45,
// artists: ['Art#1', 'Art#2'],
// album: 'Some name',
// url: 'https:////....',
// info: {},
// };
// const pallette = {
// red: '#eb4d4b',
// yellow: '#f9ca24',
// blue: '#30336b',
// };
// let color = 'yellow';
// console.log(pallette[color]);
// const fitnessData = {
// totalSteps: 400000,
// totalKms: 253.32,
// avgCalorieBurn: 2300,
// workoutsThisWeek: '5 of 7',
// avgSleep: '5:45',
// };
// fitnessData.totalSteps++;
// console.log(fitnessData.totalSteps);
// fitnessData.avgSleep = '6:00';
// fitnessData.hello = 'World';
// console.log(fitnessData);
// for (let i = 0; i < 10; i++) {
// console.log('Hello World');
// }
// for (let num = 1; num <= 10; num++) {
// console.log(`${num}*${num}=${num * num}`);
// }
// const arr = [];
// for (let num = 50; num > 0; num++) {
// arr.push(num ** 2);
// }
// 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++) {
// const movie = movies[i];
// console.log(`${movie.movieName} has a rating of ${movie.rating}`);
// }
// let fullName = 'John Doe';
// let reversedName = '';
// for (let i = fullName.length - 1; i >= 0; i--) {
// reversedName += fullName[i];
// }
// console.log(reversedName);
// 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);
// let total = 0;
// const gameBoard2 = [
// [
// [4, 64, 8, 4],
// [4, 64, 8, 4],
// [4, 64, 8, 4],
// [4, 64, 8, 4],
// ],
// [
// [4, 64, 8, 4],
// [4, 64, 8, 4],
// [4, 64, 8, 4],
// [4, 64, 8, 4],
// ],
// [
// [4, 64, 8, 4],
// [4, 64, 8, 4],
// [4, 64, 8, 4],
// [4, 64, 8, 4],
// ],
// ];
for (let i = 0; i < 10; i++) {
console.log(i);
}
let i = 0;
while (i < 10) {
console.log(i);
i++;
}
// const arr = [
// [
// [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],
// [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],
// [1, 2, 3, 4],
// [1, 2, 3, 4],
// ],
// ];
// let total = 0;
// for (let i = 0; i < arr.length; i++) {
// for (let j = 0; j < arr[i].length; j++) {
// for (let k = 0; k < arr[i][j].length; k++) {
// total += arr[i][j][k];
// }
// }
// }
// console.log(total);
// 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() * 1000) + 1;
// let guess = Math.floor(Math.random() * 1000) + 1;
// while (target !== guess) {
// console.log(`Target: ${target} | Guess: ${guess}`);
// if (guess === 13) {
// break;
// }
// guess = Math.floor(Math.random() * 1000) + 1;
// }
// console.log(`Final Result: \nTarget: ${target} | Guess: ${guess}`);
// const target = Math.floor(Math.random() * 10) + 1;
// let guess = Math.floor(Math.random() * 10) + 1;
// while (true) {
// console.log(`Target: ${target} | Guess: ${guess}`);
// if (target === guess) {
// break;
// }
// guess = Math.floor(Math.random() * 10) + 1;
// }
// console.log(`Final Result: \nTarget: ${target} | Guess: ${guess}`);
// const arr1 = [1, 2, 3, 4, 5];
// const arr2 = ['john', 'jane', 'jack', 'joe'];
// for (let i = 0; i < arr1.length; i++) {
// console.log(arr1[i]);
// }
// for (let i = 0; i < arr2.length; i++) {
// console.log(arr2[i]);
// }
// const arr1 = [1, 2, 3, 4, 5];
// const arr2 = ['john', 'jane', 'jack', 'joe'];
// for (let num of arr1) {
// console.log(num);
// }
// for (let name of arr2) {
// console.log(name);
// }
// const str = 'John Doe';
// for (let char of str) {
// console.log(char);
// }
// const matrix = [
// [1, 4, 7],
// [9, 7, 2],
// [9, 4, 6],
// ];
// for (let row of matrix) {
// for (let num of row) {
// console.log(num);
// }
// }
// const productPrices = {
// Apple: 80000,
// OnePlus: 50000,
// Samsung: 90000,
// };
// // // console.log(productPrices['Apple']);
// for (let product of Object.keys(productPrices)) {
// console.log(productPrices[product]);
// }
// for (let key in productPrices) {
// console.log(productPrices[key]);
// }
// function sayHello() {
// console.log('Hello World');
// console.log('Hello Again');
// }
// for (let i = 0; i < 50; i++) {
// sayHello();
// }
// function rollDie() {
// let roll = Math.floor(Math.random() * 6) + 1;
// console.log(`Rolled: ${roll}`);
// }
// function throwDice() {
// rollDie();
// rollDie();
// rollDie();
// }
// throwDice();
// function greet(firstName, message) {
// console.log(`${message} ${firstName}`);
// }
// greet('Hello', 'John');
// greet('Jane', 'Hello');
// function add(a, b) {
// console.log(a + b);
// }
// add(10, 5);
// function rollDie() {
// let roll = Math.floor(Math.random() * 6) + 1;
// console.log(`Rolled: ${roll}`);
// }
// // parameter
// function throwDice(times) {
// for (let i = 0; i < times; i++) {
// rollDie();
// }
// }
// throwDice(2); // argument
function greet(firstName, lastName) {
return `My name is ${firstName} ${lastName}.`;
}
const message = greet('Jane', 'Doe');
console.log(message);
// let fullName = 'Jane Smith';
// function greet() {
// let fullName = 'John Doe';
// console.log(`Hello ${fullName}`);
// }
// console.log(fullName);
// greet();
// if (true) {
// var fullName = 'John Doe';
// console.log(fullName);
// }
// console.log(fullName);
// for (var i = 0; i < 10; i++) {
// console.log(i);
// }
// console.log(i);
// function outer() {
// function inner() {
// let movieName = 'Avengers';
// console.log(movieName);
// }
// console.log(movieName);
// inner();
// }
// outer();
// function add(a, b) {
// return a + b;
// }
// const helloWorld = add;
// console.log(helloWorld(10, 5));
// // Anonoymous Function
// const add = function (a, b) {
// return a + b;
// };
// function math(a, b, fn) {
// return fn(a, b);
// }
// // console.log(add(10, 5));
// console.log(math(10, 20, add));
// console.log(
// math(10, 20, function (a, b) {
// return a - b;
// })
// );
// const arr = [
// function (a, b) {
// return a + b;
// },
// function (a, b) {
// return a - b;
// },
// function (a, b) {
// return a * b;
// },
// ];
// console.log(arr[1](10, 2));
// const maths = {
// add: function (a, b) {
// return a + b;
// },
// sub: function (a, b) {
// return a - b;
// },
// mul: function (a, b) {
// return a * b;
// },
// };
// console.log(maths.sub(10, 2));
// function greet(fn) {
// fn();
// fn();
// }
// greet(function () {
// console.log('Hello World');
// });
// setTimeout(function () {
// console.log('Hello');
// }, 3000);
// setInterval(function () {
// console.log(Math.random());
// }, 1);
// function raiseBy(num) {
// return function (x) {
// return x ** num;
// };
// }
// const square = raiseBy(2);
// console.log(square(2));
// console.log(raiseBy(2)(2));
// const square = raiseBy(2);
// const cube = raiseBy(3);
// const hypercube = raiseBy(4);
// console.log(square(2));
// console.log(cube(2));
// console.log(hypercube(2));
// function isBetween(x, y) {
// return function (num) {
// return num >= x && num <= y;
// };
// }
// const hello = isBetween(10, 20);
// console.log(hello(14));
// const isUnderAge = isBetween(0, 18);
// const canEnterButNotDrink = isBetween(18, 21);
// const canDrink = isBetween(21, 65);
// const isSenior = isBetween(65, 100);
// console.log(isUnderAge(5));
// console.log(canEnterButNotDrink(20));
// console.log(canDrink(30));
// console.log(isSenior(70));
// setTimeout(function () {
// console.log(Math.random());
// }, 1000);
// greet();
// function greet() {
// console.log('Hello World');
// }
// console.log(name);
// var name = 'John Doe';
// const arr = [1, 2, 3, 4, 5, 6];
// // for (let num of arr) {
// // console.log(num);
// // }
// arr.forEach(function (num, i) {
// console.log(`Index ${i} = ${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 + 1} - ${movie.title} has a rating of ${movie.rating}`);
// });
// const names = ['john', 'jack', 'jane', 'james'];
// const uppercasedNames2 = names.map(function (name) {
// return name.toUpperCase();
// });
// console.log(uppercasedNames2);
// const uppercasedNames = [];
// for (let name of names) {
// uppercasedNames.push(name.toUpperCase());
// }
// console.log(uppercasedNames);
// const products = [
// { name: 'Apple', price: 3 },
// { name: 'Banana', price: 2 },
// { name: 'Orange', price: 5 },
// { name: 'Vada Pav', price: 6 },
// ];
// const productInRs = products.map(function (product) {
// return { name: product.name, price: product.price * 75 };
// });
// console.log(productInRs);
const nums = [2, 3, 4, 7, 6, 8, 13, 10, 19, 12, 14, 22, 21, 16];
const numsData = nums.map(function (num) {
return {
number: num,
isEven: num % 2 === 0,
};
});
console.log(numsData);
// 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;
// });
// console.log(doubles);
// const square = function (num) {
// return num * num;
// }
// const square2 = (num) => {
// return num * num;
// }
// const square3 = (num) => (
// num * num
// )
// const square4 = num => (
// num * num
// )
// const square5 = (num, num2) => (
// num * num2
// )
// const square6 = () => (
// 10
// )
// const square7 = num => (num * num);
// const square8 = num => num * num;
// const nums = [2, 3, 4, 7, 6, 8, 13, 10, 19, 12, 14, 22, 21, 16];
// const doubles = nums.map((num) => num * 2);
// let movies = ['The Terminator', 'The Avengers', 'Jurassic Park', 'Titanic'];
// const result = movies.find((movie) => {
// return movie.includes('The');
// });
// console.log(result);
// 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 goodBook = books.filter((b) => b.rating >= 7);
// console.log(goodBook);
// const names = ['jack', 'james', 'john', 'jane', 'josh', 'jrad'];
// const res = names.some((name) => {
// return name[0] !== 'j';
// });
// console.log(res);
// const prices = [500.4, 211, 23, 5, 4, 22.2, -23.2, 9233];
// prices.sort((a, b) => a - b);
// console.log(prices);
// const nums = [1, 2, 3, 4, 5, 6];
// const result = nums.reduce((acc, currVal) => {
// return acc * currVal;
// });
// console.log(result);
// acc currVal
// 1 2
// 3 3
// 6 4
// 10 5
// 15 6
// 21
// let nums = [21, 221, 2, 1, 34, 123, 4342, 56, 4];
// const res = nums.reduce((acc, currVal) => {
// if (currVal > acc) {
// return currVal;
// }
// return acc;
// });
// console.log(res);
// acc curVal
// 21 221
// 221 2
// 221 1
// 221
// const nums = [1, 2, 3, 4, 5, 6];
// const result = nums.reduce((acc, currVal) => acc + currVal, 10);
// console.log(result);
// function multiply(a, b) {
// if (typeof a === 'undefined') {
// a = 1;
// }
// if (typeof b === 'undefined') {
// b = 1;
// }
// return a * b;
// }
function multiply(a = 1, b = 1) {
return a * b;
}
console.log(multiply(10));
// const nums = [10, 3, 50, 8, -12, 100];
// console.log(Math.min(...nums));
// function printVals(a, b, c) {
// console.log(a);
// console.log(b);
// console.log(c);
// }
// const names = ['john', 'jane', 'jack'];
// printVals(...names);
// const moderator = { canEdit: true, authority: 5 };
// const user = { canView: true, authority: 2.5 };
// const admin = { ...moderator };
// console.log(admin);
// function add(...nums) {
// let total = 0;
// for (let num of nums) {
// total += num;
// }
// console.log(total);
// }
// add(10, 5, 50, 100, -12, 34, 0.12);
// function greet(user1, user2, ...others) {
// console.log(user1);
// console.log(user2);
// console.log(others);
// }
// greet('john', 'jane', 'jack', 'james', 'joe');
// const users = ['john', 'jane', 'jack'];
// // const moderator = users[0];
// // const user = users[2];
// const [moderator, ...others] = users;
// console.log(moderator, others);
// const user = {
// firstName: 'John',
// lastName: 'Doe',
// email: 'john.doe@gmail.com',
// phone: 99982234567,
// };
// const { firstName, ...others } = user;
// console.log(firstName, others);
// const firstName = user.firstName;
// const lastName = user.lastName;
// function profile(user) {
// console.log(
// `${user.firstName} ${user.lastName} is ${user.age} years old and is a ${user.profession} by trade.`
// );
// }
// function profile({ firstName, lastName, age, profession }) {
// console.log(
// `${firstName} ${lastName} is ${age} years old and is a ${profession} by trade.`
// );
// }
// profile({
// firstName: 'Jane',
// lastName: '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;
// for (let rating of movieReviews) {
// total += rating;
// }
// const average = total / movieReviews.length;
// const info = { highest, lowest, average };
// console.log(info);
// const getReviewDetails = (arr) => {
// const highest = Math.max(...arr)
// const lowest = Math.min(...arr)
// const total = arr.reduce((accumulator, nextVal) => accumulator + nextVal)
// const average = total / arr.length
// return {
// highest,
// lowest,
// total,
// average
// }
// }
// const reviewList = [4.5, 5.0, 3.2, 2.1, 4.7, 3.8, 3.1, 3.9, 4.4]
// const statistics = getReviewDetails(reviewList)
// const username = 'janedoe';
// const role = 'admin';
// const user1 = { [role]: username };
// console.log(user1);
// const addProperty = (obj, k, v) => {
// return { ...obj, [k]: v };
// };
// console.log(addProperty({ firstName: 'john' }, 'lastName', 'Doe'));
// const math = {
// add: function (a, b) {
// return a + b;
// },
// sub: function (a, b) {
// return a - b;
// },
// square: function (num) {
// return num * num;
// },
// PI: 3.14,
// };
// console.log(math.add(10, 5));
// const math = {
// add(a, b) {
// return a + b;
// },
// sub(a, b) {
// return a - b;
// },
// square(num) {
// return num * num;
// },
// PI: 3.14,
// };
// console.log(math.add(10, 5));
// console.log('Hello World');
function namaste() {
console.log(this);
}
const user = {
firstName: 'John',
lastName: 'Doe',
greet: function () {
console.log(this.firstName);
},
};
namaste();
user.greet();
function testFunc() {
console.log(this);
}
// testFunc();
// // var aaaaaa = 'Hello World';
// let aaaaab = 'Test';
function profile() {
return `My name is ${this.firstName} ${this.lastName} and I am ${this.age} years old.`;
}
// // profile();
// const user1 = {
// firstName: 'John',
// lastName: 'Doe',
// age: 20,
// profile,
// };
// const user2 = {
// firstName: 'Jane',
// lastName: 'Smith',
// age: 22,
// profile,
// greet() {
// console.log(`${this.profile()}. SOME MORE TEXT`);
// },
// };
// // user2.profile();
// // user1.profile();
// // profile();
// user2.greet();
// // const greet2 = user1.greet;
// // // testFunc();
// // // user1.greet();
// // greet2();
// const hellos = {
// messages: [
// 'hello world',
// 'hello universe',
// 'hello darkness',
// 'hello hello',
// 'heylo',
// ],
// pickMsg() {
// const index = Math.floor(Math.random() * this.messages.length);
// return this.messages[index];
// },
// start() {
// setInterval(() => {
// // this = hellos
// console.log(this.pickMsg());
// }, 1000);
// },
// };
// hellos.start();
// const user1 = {
// firstName: 'John',
// lastName: 'Doe',
// age: 20,
// greet: () => {
// // this = window
// console.log(this.firstName);
// },
// };
// user1.greet();
// console.dir(document.body);
// const p = document.getElementById('imp');
// console.dir(p.innerText);
// const lis = document.
// getElementsByTagName('li');
// for (let li of lis) {
// console.dir(li.innerText);
// }
// const imp = document.getElementsByClassName('important');
// console.log(imp);
// const ul = document.getElementById('list');
// const imp = ul.getElementsByClassName('important');
// console.log(imp);
// const li = document.querySelector('#imp');
// const p = document.querySelector('p');
// const lis = document.querySelectorAll('li');
// const test = document.querySelectorAll('.important');
// const cls = document.querySelectorAll('[class]');
// console.log(li);
// console.log(p);
// console.log(lis);
// console.log(test);
// console.log(cls);
// const h1 = document.querySelector('h1');
// const ul = document.querySelector('ul');
// // console.log(h1.innerText);
// // h1.innerText = 'Hello World';
// // console.log(ul.innerText);
// ul.innerText = 'Hello';
// const p = document.querySelector('.special');
// // // console.log(p.innerHTML);
// // p.innerHTML = 'Hello <b>World</b>';
// const inp = document.querySelector('input');
// // inp.value = 'Hello World';
// console.log(inp.type);
// // inp.type = 'checkbox';
// p.id = 'Hello';
// const inp = document.querySelector('input');
// console.log(inp.getAttribute('value'));
// inp.setAttribute('value', 'Hello Universe');
// const item = document.querySelectorAll('.important')[1];
// console.log(item.innerText);
// // console.log(item.parentElement.parentElement.parentElement);
// // console.log(item.nextElementSibling.nextElementSibling);
// console.log(item.previousElementSibling);
const lis = document.querySelectorAll('li');
for (let li of lis) {
// li.innerText = 'hello World';
setInterval(function () {
li.innerText = Math.random();
}, 100);
}
// // const h1 = document.querySelector('h1');
// // h1.style.color = 'red';
// // h1.style.fontSize = '30px';
// // h1.style.textDecoration = 'underline';
// // document.body.style.fontFamily = 'Arial';
// // console.log(h1.style.fontWeight);
// // const colors = ['red', 'yellow', 'green', 'orange', 'teal'];
// // const fontWeight = [300, 400, 500, 600, 700];
// // setInterval(() => {
// // let random = Math.floor(Math.random() * colors.length);
// // h1.style.color = colors[random];
// // h1.style.fontWeight = fontWeight[random];
// // }, 500);
// // const h1Styles = getComputedStyle(h1);
// // console.log(h1Styles.fontWeight);
// // const item = document.querySelector('li');
// // // item.setAttribute('class', 'done');
// // console.log(item.classList);
// // item.classList.toggle('todo');
// // const root = document.querySelector('#root');
// // const h1 = document.createElement('h1');
// // h1.innerText = 'Hello World from JavaScript.';
// // h1.style.color = 'red';
// // h1.style.textDecoration = 'underline';
// // const section = document.createElement('section');
// // section.style.border = '5px solid red';
// // section.style.padding = '20px';
// // section.appendChild(h1);
// // root.appendChild(section);
// // const ul = document.querySelector('#list');
// // const li = document.querySelector('.important');
// // const newLi = document.createElement('li');
// // newLi.innerText = 'Test li element';
// // // ul.appendChild(newLi);
// // console.log(ul);
// // console.log(li);
// // ul.insertBefore(newLi, li);
// // const p = document.querySelector('p.special');
// // const b = document.createElement('b');
// // const i = document.createElement('i');
// // b.innerText = 'HELLO WORLD';
// // i.innerText = 'Goodbye World';
// // // p.insertAdjacentElement('afterend', b);
// // p.prepend(b, i);
// // // const ul = document.querySelector('#list');
// // const li = document.querySelector('.important');
// // // ul.removeChild(li);
// // li.remove();
// const colors = ['red', 'yellow', 'green', 'orange', 'teal'];
// const btn = document.querySelector('button');
// // btn.onclick = function () {
// // console.log('Hello World');
// // let random = Math.floor(Math.random() * colors.length);
// // document.body.style.backgroundColor = colors[random];
// // };
// // btn.onclick = function () {
// // console.log('GoodBye World');
// // };
// btn.addEventListener('click', function () {
// console.log('Hello');
// let random = Math.floor(Math.random() * colors.length);
// document.body.style.backgroundColor = colors[random];
// });
// btn.addEventListener('click', function () {
// console.log('Goodbye');
// });
// btn.addEventListener('mousedown', function () {
// document.body.style.backgroundColor = 'black';
// // document.body.style.fontSize = '80px';
// });
// btn.addEventListener('mouseup', function () {
// // document.body.style.backgroundColor = 'black';
// document.body.style.fontSize = '100%';
// });
// window.addEventListener('scroll', function () {
// let random = Math.floor(Math.random() * colors.length);
// document.body.style.backgroundColor = colors[random];
// });
// const btn = document.querySelector('button');
// btn.addEventListener('mouseover', function () {
// const height = Math.floor(Math.random() * window.innerHeight);
// const width = Math.floor(Math.random() * window.innerWidth);
// btn.style.left = `${width}px`;
// btn.style.top = `${height}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');
// const printColor = function () {
// console.log(this.style.backgroundColor);
// };
// for (let color of colors) {
// const box = document.createElement('div');
// 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', printColor);
// }
// btn.addEventListener('click', function (event) {
// console.log(event.ctrlKey);
// console.log(event.target);
// });
// inp.addEventListener('keypress', function (event) {
// p.innerText = event.target.value;
// });
// const btn = document.querySelector('button');
// const inp = document.querySelector('input');
// const ul = document.querySelector('ul');
// inp.addEventListener('keypress', function (event) {
// console.log(event);
// if (event.key === 'Enter') {
// const li = document.createElement('li');
// li.innerText = inp.value;
// li.addEventListener('click', function () {
// li.style.textDecoration = 'line-through';
// });
// const btn = document.createElement('button');
// btn.innerText = 'Delete';
// btn.addEventListener('click', function () {
// li.remove();
// });
// li.append(btn);
// ul.append(li);
// inp.value = '';
// }
// });
// btn.addEventListener('click', function (event) {
// const li = document.createElement('li');
// li.innerText = inp.value;
// li.addEventListener('click', function () {
// li.style.textDecoration = 'line-through';
// });
// const btn = document.createElement('button');
// btn.innerText = 'Delete';
// btn.addEventListener('click', function () {
// li.remove();
// });
// li.append(btn);
// ul.append(li);
// inp.value = '';
// });
// const form = document.querySelector('form');
// form.addEventListener('submit', function (event) {
// event.preventDefault();
// console.dir(event.target.children.fullName.value);
// console.dir(event.target.children.phone.value);
// console.dir(event.target.children.tos.checked);
// });
// const multiply = (x, y) => x * y;
// const square = (x) => multiply(x, x);
// const rightTriangle = (a, b, c) => {
// return 9 + 16 === 25;
// };
// rightTriangle(3, 4, 5);
// console.log('The first log');
// alert('An interruption in between');
// console.log('The last log');
// console.log('The first log');
// setTimeout(() => {
// console.log('The line that takes time to complete');
// }, 3000);
// console.log('The last log');
// const btn = document.querySelector('button');
// // Callback hell
// setTimeout(() => {
// // 1st
// btn.style.transform = `translateX(100px)`;
// setTimeout(() => {
// // 2nd
// btn.style.transform = `translateX(200px)`;
// setTimeout(() => {
// btn.style.transform = `translateX(300px)`;
// setTimeout(() => {
// btn.style.transform = `translateX(400px)`;
// setTimeout(() => {
// btn.style.transform = `translateX(500px)`;
// setTimeout(() => {
// btn.style.transform = `translateX(600px)`;
// }, 1000);
// }, 1000);
// }, 1000);
// }, 1000);
// }, 1000);
// }, 1000);
// const willGetAPlaystation = new Promise((resolve, reject) => {
// setTimeout(() => {
// const random = Math.random();
// if (random > 0.5) {
// resolve();
// } else {
// reject();
// }
// }, 3000);
// });
// console.log(willGetAPlaystation);
// willGetAPlaystation
// .then(() => {
// console.log('THANK YOU');
// })
// .catch(() => {
// console.log('*&*%^&$^%');
// });
// const makePlayStationPromise = () => {
// return new Promise((resolve, reject) => {
// setTimeout(() => {
// const rand = Math.random();
// if (rand < 0.5) {
// resolve({ hello: 'World' });
// } else {
// reject({ error: 'Some error ' });
// }
// }, 1000);
// });
// };
// const res = makePlayStationPromise();
// res
// .then((data) => {
// console.log(data);
// })
// .catch((error) => {
// console.log(error);
// });
// // console.log(res);
const fakeRequest = (url) => {
return new Promise((resolve, reject) => {
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 });
}
});
};
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);
})
.catch((error) => {
console.log(error);
});
// // const res = fetch('https://swapi.dev/api/peosdxfple/1');
// // res
// // .then((response) => {
// // if (!response.ok) {
// // throw 'DID NOT WORK';
// // }
// // return response.json();
// // })
// // .then((res) => {
// // console.log(res);
// // })
// // .catch((err) => console.log(err));
// // const res = axios.get('https://swapi.dev/api/people');
// // res
// // .then((response) => {
// // const luke = response.data.results[0];
// // const film = luke.films[0];
// // return axios.get(film);
// // })
// // .then(({ data }) => {
// // console.log(data);
// // })
// // .catch((err) => {
// // console.log(err.message);
// // });
// function test1() {
// return new Promise((resolve, reject) => {
// const random = Math.random();
// if (random > 0.5) {
// resolve('fulfilled');
// } else {
// reject();
// }
// });
// }
// async function test2() {
// const random = Math.random();
// if (random > 0.5) {
// return 'fulfilled';
// } else {
// throw 'rejected';
// }
// }
// const res = test2();
// res
// .then((res) => {
// console.log(res);
// })
// .catch((err) => {
// console.log(err);
// });
// // const res = test1();
// // console.log(res);
// function getData() {
// const response = axios.get('https://swapi.dev/api/people/1');
// response.then((res) => {
// console.log(res.data);
// });
// }
// async function getData() {
// try {
// const response = await axios.get('https://swapi.dev/api/people/1');
// console.log(response.data);
// } catch (err) {
// console.log(err.message);
// }
// }
// getData();
async function getData() {
const poke1Request = axios.get('https://pokeapi.co/api/v2/pokemon/1');
const poke2Request = axios.get('https://pokeapi.co/api/v2/pokemon/2');
const poke3Request = axios.get('https://pokeapi.co/api/v2/pokemon/3');
// const poke1 = await poke1Request;
// const poke2 = await poke2Request;
// const poke3 = await poke3Request;
const result = await Promise.all([poke1Request, poke2Request, poke3Request]);
console.log(result[0]);
console.log(result[1]);
console.log(result[2]);
}
getData();
// // function initializeDeck() {
// // const deck = [];
// // const suits = ['hearts', 'diamonds', 'spades', 'clubs'];
// // const values = '2,3,4,5,6,7,8,9,10,J,Q,K,A';
// // for (let value of values.split(',')) {
// // for (let suit of suits) {
// // deck.push({ value, suit });
// // }
// // }
// // return deck;
// // }
// // function drawCard(deck, drawnCards) {
// // const card = deck.pop();
// // drawnCards.push(card);
// // return card;
// // }
// // function drawMultiple(numCards, deck, drawnCards) {
// // const cards = [];
// // for (let i = 0; i < numCards; i++) {
// // cards.push(drawCard(deck, drawnCards));
// // }
// // return cards;
// // }
// // function shuffle(deck) {
// // for (let i = deck.length - 1; i > 0; i--) {
// // let j = Math.floor(Math.random() * (i + 1));
// // [deck[i], deck[j]] = [deck[j], deck[i]];
// // }
// // return deck;
// // }
// // const deck1 = initializeDeck();
// // shuffle(deck1);
// // const hand = [];
// // // drawCard(deck1, hand);
// // // drawCard(deck1, hand);
// // // drawCard(deck1, hand);
// // // drawMultiple(4, deck1, hand);
// // console.log(deck1);
// const makeDeck = () => {
// return {
// deck: [],
// drawnCards: [],
// suits: ['hearts', 'diamonds', 'spades', 'clubs'],
// values: '2,3,4,5,6,7,8,9,10,J,Q,K,A',
// initializeDeck() {
// for (let value of this.values.split(',')) {
// for (let suit of this.suits) {
// this.deck.push({ value, suit });
// }
// }
// return this.deck;
// },
// drawCard() {
// const card = this.deck.pop();
// this.drawnCards.push(card);
// return card;
// },
// drawMultiple(numCards) {
// const cards = [];
// for (let i = 0; i < numCards; i++) {
// cards.push(this.drawCard());
// }
// return cards;
// },
// shuffle() {
// const { deck } = this;
// for (let i = deck.length - 1; i > 0; i--) {
// let j = Math.floor(Math.random() * (i + 1));
// [deck[i], deck[j]] = [deck[j], deck[i]];
// }
// },
// };
// };
// const deck1 = makeDeck();
// const deck2 = makeDeck();
// const deck3 = makeDeck();
// // deck1.initializeDeck();
// // deck1.shuffle();
// // deck1.drawCard();
// // deck1.drawCard();
// // deck1.drawMultiple(4);
// console.log(deck1);
// console.log(deck2);
// console.log(deck3);
// function Person(firstName, lastName, age) {
// this.firstName = firstName;
// this.lastName = lastName;
// this.age = age;
// }
// Person.prototype.greet = function () {
// console.log(`Hello, my name is ${this.firstName} ${this.lastName}`);
// };
// Person.prototype.profession = 'Full-Stack Developer';
// const jane = new Person('jane', 'doe', 20);
// const jack = new Person('jack', 'smith', 23);
// console.log(jane);
// console.log(jack);
// class Person {
// constructor(firstName, lastName, age) {
// this.firstName = firstName;
// this.lastName = lastName;
// this.age = age;
// }
// greet() {
// console.log(`Hello, my name is ${this.firstName} ${this.lastName}`);
// }
// }
// const jane = new Person('jane', 'doe', 20);
// const jack = new Person('jack', 'smith', 23);
// console.log(jane);
// console.log(jack);
// class Deck {
// constructor() {
// this.deck = []
// this.drawnCards = []
// this.suits = ['hearts', 'diamonds', 'spades', 'clubs']
// this.values = '2,3,4,5,6,7,8,9,10,J,Q,K,A'
// }
// initializeDeck() {
// const { suits, values, deck } = this
// for (let value of values.split(',')) {
// for (let suit of suits) {
// deck.push({ value, suit })
// }
// }
// return deck
// }
// drawCard() {
// const card = this.deck.pop()
// this.drawnCards.push(card)
// return card
// }
// drawMultiple(numCards) {
// const cards = []
// for (let i = 0; i < numCards; i++) {
// cards.push(this.drawCard())
// }
// return cards
// }
// shuffle() {
// const { deck } = this
// for (let i = deck.length - 1; i > 0; i--) {
// let j = Math.floor(Math.random() * (i + 1))
// ;[deck[i], deck[j]] = [deck[j], deck[i]]
// }
// }
// }
// const deck1 = new Deck()
// deck1.initializeDeck()
// deck1.shuffle()
// const deck2 = new Deck()
// deck2.initializeDeck()
// deck2.shuffle()
// deck1.drawCard()
// deck2.drawCard()
// deck2.drawCard()
// deck2.drawMultiple(2)
// console.log(deck1)
// console.log(deck2)
class User {
constructor(username, password) {
this.username = username;
this.password = password;
}
login(pass) {
if (pass === this.password) {
console.log('Welcome back');
} else {
console.log('Incorrect password entered.');
}
}
}
class Admin extends User {
constructor(username, password, email) {
super(username, password);
this.email = email;
}
createGroup(groupName) {
console.log('New group created. ', groupName);
}
}
const jane = new User('jane', 'jane123');
const john = new Admin('john', 'john123');
john.login('john123');
john.createGroup('JavaScript');
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