console.log('Hello World');
let greeting = 'Hello World, Welcome to RST Forum.';
greeting.toUpperCase().toLowerCase();
// let age = 15;
// if (age >= 65) {
// console.log('Drinks are free');
// } else if (age >= 21) {
// console.log('You can enter and drink');
// } else if (age >= 18) {
// console.log("You can enter but you can't drink");
// } else {
// console.log("You can't enter");
// }
// if (age % 2 === 0) {
// console.log('Even number');
// }
// let password = 'hello world@123';
// if (password.length >= 6) {
// if (password.indexOf(' ') !== -1) {
// console.log('Password cannot contain spaces');
// } else {
// console.log('Valid password');
// }
// } else {
// console.log('Invalid password');
// }
// let loggedInUser = null;
// if (loggedInUser) {
// console.log('Here is the content');
// } else {
// console.log('Please login to view this content');
// }
// let age = 80;
// if (age >= 18 && age < 21) {
// console.log("You can 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('Drinks are free');
// } else {
// console.log("You can't enter");
// }
// let day = 4;
// if (day === 1) {
// console.log('Monday');
// } else if (day === 2) {
// console.log('Tuesday');
// } else if (day === 3) {
// console.log('Wednesday');
// }
// let day = 24;
// switch (day) {
// case 1:
// console.log('Monday');
// break;
// case 2:
// console.log('Tuesday');
// break;
// case 3:
// console.log('Wednesday');
// break;
// case 4:
// console.log('Thursday');
// break;
// case 5:
// console.log('Friday');
// break;
// case 6:
// console.log('Saturday');
// break;
// case 7:
// console.log('Sunday');
// break;
// default:
// console.log('Invalid day code');
// }
// let num = 11;
// if (num % 2 === 0) {
// console.log('Even');
// } else {
// console.log('Odd');
// }
// num % 2 === 0 ? console.log('Even') : console.log('Odd');
let statusMsg = 'online';
// let color = null;
let color = statusMsg === 'offline' ? 'red' : 'green';
// if (statusMsg === 'offline') {
// color = 'red';
// } else {
// color = 'green';
// }
console.log(color);
// let movs = [
// 'Avengers',
// 'Mission Impossible',
// 'Black Panther',
// 'The Godfather',
// 'Race 3',
// 'Alien',
// 'Black Panther',
// 'Avengers',
// ];
// console.log(movs.join(','));
let product1 = ['iPhone 14', 'Apple', 500, 100000, 'Some description...', true];
let product2 = ['Nord 2', 'One Plus', 30000, 1000, 'Some description...', true];
// let products = [product1, product2];
console.log(product1[0]);
let product3 = {
brand: 'Apple',
inStock: 500,
description: 'Some desc...',
price: 100000,
name: 'iPhone 14',
exchangeAvail: true,
100: 'hello',
'hello world': true,
};
console.log(product3.price);
// // let arr1 = [1, 2, 3];
// // let arr1 = { 0: 1, 1: 2, 2: 3, length: 3 };
// // const playlist = [
// // {
// // trackName: 'Song #1',
// // trackLength: 3.52,
// // album: 'Album #1',
// // artists: [
// // {
// // name: 'Person 1',
// // age: 30,
// // },
// // ],
// // },
// // {
// // trackName: 'Song #1',
// // trackLength: 3.52,
// // album: 'Album #1',
// // artists: ['Person 1', 'Person 2'],
// // },
// // ];
// // const student = {
// // firstName: 'John',
// // lastName: 'Doe',
// // frameworks: ['ReactJS', 'Express.js'],
// // levels: {
// // backend: 50,
// // frontend: 45,
// // data: 5,
// // },
// // };
// // console.log(student.levels.data);
// // console.log(student.frameworks[1]);
// // for (let i = 0; i < 10; i++) {
// // console.log(i, 'Hello World');
// // }
// // for (let num = 1; num <= 10; num++) {
// // console.log(`${num}*${num}=${num * num}`);
// // }
// // for (let i = 100; i > 0; i -= 10) {
// // 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 i = 0; i < word.length; i++) {
// // console.log(word[i]);
// // }
// // let reversedWord = '';
// // for (let i = word.length - 1; i >= 0; i--) {
// // reversedWord = reversedWord + word[i];
// // }
// // console.log(reversedWord);
// // for (let i = 0; i < 5; i++) {
// // console.log('OUTER LOOP', i);
// // for (let j = 0; j < 5; j++) {
// // console.log(' INNER LOOP', 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++) {
// // console.log(gameBoard[i]);
// for (let j = 0; j < gameBoard[i].length; j++) {
// // console.log(gameBoard[i][j]);
// total += gameBoard[i][j];
// }
// }
// console.log(total);
// // const gameBoard = [
// // [
// // [4, 64, 8, 4, 4, 5],
// // [4, 64, 8],
// // [4],
// // [4, 64, 8, 4, 12, 2, 3, 234, 54, 6456],
// // ],
// // [`
// // [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 < 5; i++) {
// console.log(i);
// }
// let i = 0;
// while (i < 5) {
// console.log(i);
// i++;
// }
// const target = Math.floor(Math.random() * 10);
// let guess = Math.floor(Math.random() * 10);
// let count = 1;
// while (guess !== target) {
// console.log(`Target: ${target} | Guess: ${guess}`);
// guess = Math.floor(Math.random() * 10);
// count++;
// }
// console.log(count);
// console.log(`Target: ${target} | Guess: ${guess}`);
// const target = Math.floor(Math.random() * 10);
// let guess = Math.floor(Math.random() * 10);
// while (true) {
// console.log(`Target: ${target} | Guess: ${guess}`);
// if (guess === target) {
// break;
// }
// guess = Math.floor(Math.random() * 10);
// }
// console.log(`Target: ${target} | Guess: ${guess}`);
// for (let i = 0; i < 10; i++) {
// console.log(i);
// if (i === 5) {
// break;
// }
// }
// let categories = [
// 'fashion',
// 'electronics',
// 'mobiles',
// 'books',
// 'toys',
// 'groceries',
// ];
// for (let i = 0; i < categories.length; i++) {
// console.log(categories[i]);
// }
// for (let category of categories) {
// console.log(category);
// }
// for (let char of 'Hello World') {
// 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 cats = ['fashion', 'mobiles', 'books'];
// const prods = ['tshirt', 'samsung', '1984'];
// for (let i = 0; i < cats.length; i++) {
// console.log(cats[i], prods[i]);
// }
// const productPrices = {
// Apple: 80000,
// OnePlus: 50000,
// Samsung: 90000,
// };
// for (let key of Object.keys(productPrices)) {
// console.log(key, productPrices[key]);
// }
// for (let key in productPrices) {
// console.log(key, productPrices[key]);
// }
// for (let key of Object.keys(productPrices)) {
// console.log(key);
// }
// for (let value of Object.values(productPrices)) {
// console.log(value);
// }
const movieRating = {
pursuitOfHappiness: 4.8,
satya: 4.8,
gangsOfWasepur: 4,
robot: -3,
};
for (let movie in movieRating) {
// console.log(movie)
console.log(`${movie} has a rating of ${movieRating[movie]}`);
}
// function greet() {
// console.log('Hello World');
// }
// greet();
// function rollDie() {
// let roll = Math.floor(Math.random() * 6) + 1;
// console.log(`Rolled: ${roll}`);
// }
// function throwDice() {
// rollDie();
// rollDie();
// rollDie();
// }
// throwDice();
// console.log('hello world');
// // person - parameter
// function greet(person) {
// console.log(`Hello ${person}`);
// }
// greet('John Doe'); // argument
// greet('Jane Doe'); // argument
// greet('Jill Smith'); // argument
// function greet(message, person) {
// console.log(`${message}, ${person}`);
// }
// greet('Hello', 'John');
// greet('Hi', 'John');
// greet('Hi');
// greet('hi', 'john', 'jane', 'jack');
// function rollDie() {
// let roll = Math.floor(Math.random() * 6) + 1;
// console.log(`Rolled: ${roll}`);
// }
// function throwDice(times) {
// for (let i = 0; i < times; i++) {
// rollDie();
// }
// }
// throwDice(2);
// let firstName = 'John';
// firstName.toUpperCase();
// function add(x, y) {
// return x + y;
// }
// console.log(add(10, 5));
// function isNumber(val) {
// if (typeof val === 'number') {
// return true;
// }
// return false;
// }
// isNumber('10');
// let firstName = 'Jane';
// function greet() {
// let firstName = 'John';
// console.log(firstName);
// }
// greet();
// console.log(firstName);
// let lastName = 'Doe';
// if (true) {
// var lastName = 'Smith';
// console.log(lastName);
// }
// console.log(lastName);
// for (var i = 0; i < 10; i++) {
// console.log(i);
// }
// console.log('OUTSIDE THE BLOCK', i);
// function outer() {
// let message = 'Hello World';
// function inner() {
// let message = 'Goodbye';
// console.log(message);
// }
// console.log(message);
// inner();
// }
// outer();
// // Named function
// function square(num) {
// return num ** 2;
// }
// console.log(square);
// const sq = square;
// const num = 'Hello';
// console.log(sq(10));
// console.log(square(10));
// // Named function
// function square(num) {
// return num ** 2;
// }
// const sq = function (num) {
// return num ** 2;
// };
// console.log(sq(100));
// function math(x, y, fn) {
// return fn(x, y);
// }
// function add(a, b) {
// return a + b;
// }
// function sub(a, b) {
// return a - b;
// }
// console.log(math(10, 5, sub));
// console.log(
// math(10, 5, function (a, b) {
// return a * b;
// })
// );
// const math = [
// function (a, b) {
// return a + b;
// },
// function (a, b) {
// return a - b;
// },
// function (a, b) {
// return a * b;
// },
// function (a, b) {
// return a / b;
// },
// ];
// console.log(math[0](10, 5));
// 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));
function add(x, y) {
return x + y;
}
const sub = function (x, y) {
return x - y;
};
const mul = function (x, y) {
return x * y;
};
function div(x, y) {
return x / y;
}
const operations = [add, sub, mul, div];
console.log(operations[0]);
console.log(operations[0](10, 23));
console.log(operations[2](10, 4));
var hello;
// // function math(a, b, fn) {
// // return fn(a, b);
// // }
// // console.log(
// // math(10, 20, function (a, b) {
// // return a + b;
// // })
// // );
// // // Example 2
// // 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);
// // // Example 3
// // function randomPick(f1, f2) {
// // let randNum = Math.random();
// // if (randNum < 0.5) {
// // f1();
// // } else {
// // f2();
// // }
// // }
// // randomPick(sayHello, sayGoodbye);
// // function raiseBy(num) {
// // return function (x) {
// // return x ** num;
// // };
// // }
// // // const n = Math.random();
// // const square = raiseBy(2);
// // const cube = raiseBy(3);
// // const hypercube = raiseBy(4);
// // console.log(square(5));
// // console.log(cube(5));
// // console.log(hypercube(5));
// function isBetween(x, y) {
// return function (val) {
// return val >= x && val < y;
// };
// }
// const isUnderAge = isBetween(18, 21);
// const isLegalAge = isBetween(21, 65);
// console.log(isLegalAge(18));
// function isBetween(x, y) {
// return function (num) {
// return num >= x && num <= y;
// };
// }
// 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));
// function math(a, b, fn) {
// return fn(a, b);
// }
// function add(a, b) {
// return a + b;
// }
// console.log(math(10, 5, add));
// console.log(
// math(10, 5, function (a, b) {
// return a - b;
// })
// );
// function hello() {
// console.log('Hello World');
// }
// // setTimeout(hello, 2000);
// setInterval(hello, 1000);
// hello();
// function hello() {
// console.log('Hello World');
// }
// let hello = 'Hello World';
// console.log(hello);
// const arr1 = [1, 2, 3, 4, 5];
// for (let num of arr1) {
// console.log();
// }
// for (let num of arr1) {
// console.log(num);
// }
// arr1.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);
// });
// const names = ['john', 'jack', 'jane', 'james'];
// const upperNames = names.map(function (name) {
// return name.toUpperCase();
// });
// console.log(upperNames);
// const upper_names = [];
// for (let name of names) {
// upper_names.push(name.toUpperCase());
// }
// console.log(upper_names);
// 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 numDetails = nums.map(function (num) {
// return {
// number: num,
// isEven: num % 2 === 0,
// };
// });
// console.log(numDetails);
// function square(x) {
// return x * x
// }
// const square = function (x) {
// return x * x;
// }
// const square = (x) => {
// return x * x;
// }
// const square = x => {
// return x * x;
// }
// const square = x => (
// x * x
// )
// const square = x => (x * x);
// const square = x => x * x;
// console.log(square(10));
// 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 => num * 2);
// let movies = ['The Terminator', 'The Avengers', 'Jurassic Park', 'Titanic'];
// const result = movies.find(function (movie) {
// return movie[0] === 'J';
// });
// console.log(result);
// const result = movies.find((movie) => {
// return movie.includes('Hello');
// });
// 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 result = books.find((book) => book.rating < 4);
// // const result = books.find((book) => book.author.includes('George'));
// const result = books.filter((book) => book.rating < 4);
// console.log(result);
// const goodBook = books.filter(b => b.rating >= 4.3)
// const georgeBooks = books.filter(b => (
// b.author.includes('George')
// ))
// const lowRated = books.filter(book => {
// return book.rating < 4
// })
// let query = 'the'
// const filteredBooks = books.filter(book => {
// const title = book.title.toLowerCase()
// return title.includes(query)
// })
// console.log(goodBook)
// console.log(georgeBooks)
// console.log(lowRated)
// console.log(booksWithThe)
const names = ['jack', 'james', 'john', 'jane', 'josh', 'brad'];
const result = names.some((name) => name[0] === 'j');
console.log(result);
// const prices = [500.4, 211, 23, 5, 4, 22.2, -23.2, 9233];
// // prices.sort((a, b) => a - b);
// prices.sort((a, b) => b - a);
// console.log(prices);
// const arr1 = [1, 2, 3, 4, 5];
// // acc currVal
// // 1 2
// // 3 3
// // 6 4
// // 10 5
// // 15
// // const result = arr1.reduce((acc, currVal) => {
// // return acc + currVal;
// // });
// const result = arr1.reduce((acc, currVal) => {
// return acc * currVal;
// });
// console.log(result);
// let nums = [21, 221, 2, 1, 34, 123, 4342, 56, 4];
// // acc currVal
// // 21 221
// // 221 2
// // 221 1
// // 221 34
// // 221 123
// // 221 4342
// // 4342 ...
// const maxVal = nums.reduce((acc, currVal) => {
// if (currVal > acc) {
// return currVal;
// }
// return acc;
// });
// console.log(maxVal);
// // A shorter way is to use the Math.max and implicit return
// const maxVal = nums.reduce((max, currVal) => Math.max(max, currVal))
// console.log(maxVal)
// const arr1 = [1, 2, 3, 4, 5];
// const result = arr1.reduce((acc, currVal) => {
// return acc + currVal;
// }, 100);
// console.log(result);
// function multiply(a, b) {
// 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, 2, 45, 7];
// console.log(Math.max(...nums));
// function printVals(a, b, c) {
// console.log(a);
// console.log(b);
// console.log(c);
// }
// const names = ['john', 'jack', 'jane', 'jill'];
// // printVals(...names);
// printVals(...'John');
// function add(...nums) {
// let total = 0;
// for (let num of nums) {
// total += num;
// }
// return total;
// }
// console.log(add(10, 5, 12));
// function printNames(name1, name2, ...others) {
// console.log(name1);
// console.log(name2);
// console.log(others);
// }
// printNames('John', 'Jane', 'jack', 'jill', 'james');
// const users = ['john', 'jane', 'jack'];
// // const admin = users[0];
// // const mod = 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 = user.firstName;
// // const lastName = user.lastName;
// // const { firstName, lastName, email: emailAddress, phone } = user;
// const { firstName, lastName, ...others } = user;
// console.log(firstName, lastName, others);
// function profile({ firstName, lastName, profession }) {
// console.log(`My name is ${firstName} ${lastName} and I am a ${profession}`);
// }
// profile({ firstName: 'John', lastName: 'Doe', profession: 'Dev' });
// 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 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);
// console.log(statistics);
// const username = 'janedoe';
// const role = 'admin';
// // const user1 = { [role]: username };
// const user1 = { [1 + 2 + 3 + 4]: username };
// console.log(user1);
// const addProperty = (obj, k, v) => {
// return { ...obj, [k]: v };
// };
// console.log(addProperty({ firstName: 'john' }, 'lastName', 'Doe'));
const math = {
multiply(x, y) {
return x * y;
},
divide(x, y) {
return x / y;
},
square(x) {
return x * x;
},
PI: 3.14,
};
console.log(math.square(5));
// // // // Global Scope {}
// // // // let firstName = 'John';
// // // let firstName = 'John';
// // // function namaste() {
// // // // Local Scope
// // // // console.log(firstName);
// // // console.log(this);
// // // }
// // // namaste();
// // // // const profile = {
// // // // firstName: 'John',
// // // // lastName: 'Doe',
// // // // age: 20,
// // // // greet() {
// // // // console.log(this);
// // // // },
// // // // };
// // // // namaste();
// // // // profile.greet();
// // function greet() {
// // console.log(
// // `Hello, my name is ${this.firstName} ${this.lastName} and I am ${this.age} years old.`
// // );
// // }
// // // greet();
// // const john = {
// // firstName: 'John',
// // lastName: 'Doe',
// // age: 22,
// // greet,
// // };
// // const jane = {
// // firstName: 'Jane',
// // lastName: 'Smith',
// // age: 20,
// // greet,
// // };
// // jane.greet();
// // // const user = {
// // // firstName: 'Jane',
// // // lastName: 'Doe',
// // // age: 20,
// // // };
// // // user.greet();
// // 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 log = user.logDetails;
// // log();
// 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 = window
// console.log(this.pickMsg());
// }, 1000);
// },
// };
// // hellos.start();
// console.dir(document);
// const para = document.getElementById('special');
// console.dir(para);
// const lis = document.getElementsByTagName('li');
// console.log(lis);
// const ps = document.getElementsByClassName('red-text');
// console.log(ps);
// const lst = document.getElementsByClassName('my-list');
// // console.log(lst[0]);
// const lis = lst[0].getElementsByTagName('li');
// console.log(lis);
// const spc = document.querySelectorAll('li');
// console.log(spc);
// const h1 = document.querySelector('h1');
// // console.log(h1.innerText);
// h1.innerText = 'THIS HAS CHANGED!';
// const para = document.querySelector('.special');
// console.log(para.textContent);
// const para = document.querySelector('.red-text');
// para.innerHTML = 'Hello <b>World</b>';
// para.innerHTML += '<i> This is some more text</i>';
const inp = document.querySelector('input');
const a = document.querySelector('a');
inp.id = 'helloworld';
inp.value = 'Hello World';
a.href = 'https://yahoo.com';
// console.log(inp.id);
// console.log(a.href);
// const link = document.querySelector('a');
// console.log(link.href);
// console.log(link.getAttribute('href'));
// link.href = 'https://yahoo.com';
// link.setAttribute('href', 'https://yahoo.com');
// const ul = document.querySelector('ul');
// const li = ul.querySelector('li');
// // console.log(li.parentElement.parentElement);
// // console.log(ul.children);
// // console.log(li.nextElementSibling.nextElementSibling.innerText);
// console.log(li.previousElementSibling);
// const lis = document.querySelectorAll('li');
// for (let li of lis) {
// li.innerText = 'CHANGED!';
// }
// const h1 = document.querySelector('h1');
// h1.style.color = 'red';
// h1.style.backgroundColor = 'yellow';
// h1.style.padding = '20px 40px';
// const lis = document.querySelectorAll('li');
// const colors = ['red', 'yellow', 'green', 'orange', 'teal'];
// for (let li of lis) {
// li.style.color = colors[Math.floor(Math.random() * colors.length)];
// li.style.fontSize = '20px';
// li.style.fontWeight = 'bold';
// li.style.backgroundColor = 'black';
// }
// const h1 = document.querySelector('h1');
// const h1Styles = getComputedStyle(h1);
// console.log(h1Styles.backgroundColor);
// const t1 = document.querySelector('.todo');
// console.log(t1.innerText);
// t1.setAttribute('class', 'todo done');
// t1.classList.add('done');
// t1.classList.remove('todo');
// t1.classList.toggle('todo');
// console.log(t1.classList);
// const root = document.querySelector('#root');
// const h2 = document.createElement('h2');
// h2.innerText = 'I was created using JavaScript';
// h2.style.fontFamily = 'Arial';
// h2.style.color = 'blue';
// const section = document.createElement('section');
// section.style.padding = '20px 40px';
// section.style.border = '4px dashed black';
// section.appendChild(h2);
// root.appendChild(section);
// const list = document.querySelector('.my-list');
// const newTask = document.createElement('li');
// newTask.innerText = 'One more task';
// const task1 = document.querySelector('.my-list li');
// // console.log(task1.innerText);
// // list.appendChild(newTask);
// list.insertBefore(newTask, task1);
// const p = document.querySelector('.red-text');
// const b = document.createElement('b');
// b.innerText = 'Hello World';
// const i = document.createElement('i');
// i.innerText = 'Hello Universe';
// // p.insertAdjacentElement('afterend', b);
// p.prepend(b, i);
// // const list = document.querySelector('.my-list');
// const task1 = document.querySelector('.my-list li');
// // console.log(task1);
// // list.removeChild(task1);
// task1.remove();
// const btn = document.querySelector('button');
// console.log(btn);
// btn.onclick = function () {
// console.log('Hello World');
// };
// btn.onclick = function () {
// console.log('Hello Universe');
// };
// btn.addEventListener('click', function () {
// console.log(Math.random());
// });
// btn.addEventListener('click', function () {
// console.log('hello world');
// });
// btn.addEventListener('mouseenter', function () {
// document.body.style.backgroundColor = 'yellow';
// });
// btn.addEventListener('mouseout', function () {
// document.body.style.backgroundColor = 'white';
// });
// window.addEventListener('scroll', function () {
// console.log(Math.random());
// });
// const btn = document.querySelector('button');
// btn.style.position = 'relative';
// 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 () {
// document.body.style.backgroundColor = 'green';
// btn.innerText = 'You won!';
// });
// const colors = [
// 'red',
// 'orange',
// 'yellow',
// 'green',
// 'blue',
// 'purple',
// 'indigo',
// 'violet',
// ];
// const container = document.querySelector('#boxes');
// 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
// box.addEventListener('click', function () {
// console.log(box.style.backgroundColor);
// });
// }
// const inp = document.querySelector('input');
// const button = document.querySelector('button');
// const allTasks = document.querySelector('#allTasks');
// button.addEventListener('click', function (event) {
// console.dir(event.target);
// // div
// // checkbox -> click
// // span
// // button -> delete
// const li = document.createElement('li');
// li.innerText = inp.value;
// const del = document.createElement('button');
// del.innerText = 'Delete';
// li.append(del);
// allTasks.append(li);
// li.addEventListener('click', function () {
// li.remove();
// });
// inp.value = '';
// });
const inp = document.querySelector('input');
// const p = document.querySelector('p');
const allTasks = document.querySelector('#allTasks');
inp.addEventListener('keypress', function (event) {
// p.innerText = event.target.value;
if (event.key === 'Enter') {
const li = document.createElement('li');
li.innerText = event.target.value;
allTasks.append(li);
inp.value = '';
}
});
// function multiply(x, y) {
// return x * y;
// }
// function square(x) {
// return multiply(x, x);
// }
// function rightTriangle(a, b, c) {
// return square(a) + square(b) === square(c);
// }
// rightTriangle(1, 2, 3);
// console.log('The first log');
// alert('Hello World');
// console.log('The second log');
// console.log('The first log');
// setTimeout(function () {
// console.log('Long process completed. Here is your output ----> OUTPUT');
// }, 3000);
// console.log('The second log');
// const btn = document.querySelector('button');
// setTimeout(function () {
// btn.style.transform = 'translateX(100px)';
// setTimeout(function () {
// btn.style.transform = 'translateX(200px)';
// setTimeout(function () {
// btn.style.transform = 'translateX(300px)';
// setTimeout(function () {
// btn.style.transform = 'translateX(400px)';
// setTimeout(function () {
// btn.style.transform = 'translateX(500px)';
// }, 1000);
// }, 1000);
// }, 1000);
// }, 1000);
// }, 1000);
// const willGetAPlaystation = new Promise((resolve, reject) => {
// const random = Math.random();
// if (random < 0.5) {
// reject();
// } else {
// resolve();
// }
// });
// willGetAPlaystation
// .then(() => {
// console.log('Thanks for the playstation.');
// })
// .catch(() => {
// console.log('&*%^%*&^%');
// });
const makePlayStationPromise = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
const random = Math.random();
if (random < 0.5) {
reject();
} else {
resolve();
}
}, 2000);
});
};
makePlayStationPromise()
.then(() => {
console.log('Thanks for the playstation.');
})
.catch(() => {
console.log('&*%^%*&^%');
});
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
1. PUSH YOUR CODE TO GITLAB
git config –global user.name “YOUR NAME”
git config –global user.email “YOUR EMAIL”
git init
git add .
git commit -m “Ready for deployment”
git remote add origin https://gitlab.com/YOUR-USERNAME/rststore.git
git push -u origin master
(will ask for username and password)
2. INSTALL NODEJS
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash – &&\
sudo apt-get install -y nodejs
3. INSTALL MONGODB
wget -qO – https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add –
echo “deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse” | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
sudo apt-get update
echo “deb http://security.ubuntu.com/ubuntu focal-security main” | sudo tee /etc/apt/sources.list.d/focal-security.list
sudo apt-get update
sudo apt-get install libssl1.1
sudo apt-get install -y mongodb-org
sudo rm /etc/apt/sources.list.d/focal-security.list
sudo systemctl start mongod
4. SETUP
ls
cd rststore
npm install
cd frontend/
npm install
cd ..
ls -a (make sure you have .env file)
npm run data:import
npm run start
——- CHANGE PORT NUMBER TO 80 ——–
Edit your .env file and change PORT=80
git add .
git commit -m “Changed port to 80”
git push
——- ON THE UBUNTU SERVER ————
git pull (make sure you are in the project folder)
5. Setup PM2
sudo npm install -g pm2
pm2 start backend/server.js