Menu

Full Stack Daily Evening Feb 2023

Full Stack Daily Evening Feb 2023

Download HTML ZIP

Scratchpad #3

// let age = 13;

// if (age > 18) {
// 	console.log(age);
// }

// let num = 23;

// if (num % 2 === 0) {
// 	console.log('EVEN');
// }

// if (num % 2 !== 0) {
// 	console.log('ODD');
// }

// let age = 24;

// if (age > 65) {
// 	console.log('Drinks are free');
// } else if (age >= 21) {
// 	console.log('You can enter and you can drink');
// } else if (age >= 18) {
// 	console.log('You can enter but you cannot drink');
// } else {
// 	console.log('Not allowed. You cannot enter.');
// }

// let password = 'helloworld@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 = 'john';

// if (loggedInUser) {
// 	console.log('Welcome to your dashboard');
// } else {
// 	console.log('Please login to see this');
// }

// let age = 24;

// if (age >= 18 && age < 21) {
// 	console.log('You can enter but you cannot drink');
// } else if (age >= 21 && age < 65) {
// 	console.log('You can enter and you can drink');
// } else if (age >= 65) {
// 	console.log('Drinks are free');
// } else {
// 	console.log('Not allowed. You cannot enter.');
// }

// let day = 1;

// 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 age = 100;

// age > 18 ? console.log('You are allowed') : console.log('Not allowed');

// if (age > 18) {
// 	console.log('You are allowed');
// } else {
// 	console.log('Not allowed');
// }

let currStatus = 'online';

let color =
	currStatus === 'online'
		? 'green'
		: currStatus === 'offline'
		? 'red'
		: 'yellow';

// let color;

// if (currStatus === 'online') {
// 	color = 'green';
// } else if (currStatus === 'offline') {
// 	color = 'red';
// } else {
// 	color = 'yellow';
// }

console.log(color);

Scratchpad #4

// // // const product1 = ['iPhone', 'Apple', 'Some desc....', 150000, 100, true];

// // // const products = [
// // // 	['iPhone', 'Apple', 'Some desc....', 150000, 100, true],
// // // 	['One Plus Nord', 'One Plus', 'Some desc....', 150000, 100, true],
// // // 	['Galaxy s10000', 'Samsung', 'Some desc....', 150000, 100, true],
// // // 	['Apple Watch', 'Apple', 'Some desc....', 100, 100000, true],
// // // ];

// // // const product1 = ['iPhone', 'Apple', 'Some desc....', 150000, 100, true];

// // const product2 = {
// // 	price: 150000,
// // 	brand: 'Apple',
// // 	description: 'Some desc....',
// // 	name: 'iPhone',
// // 	inStock: 100,
// // 	discounted: true,
// // 	100: 'hello',
// // 	'hello world': 100,
// // };

// // console.log(product2.inStock);
// // console.log(product2[100]);
// // console.log(product2['hello world']);

// // // const product1 = ['iPhone', 'Apple', 'Some desc....', 150000, 100, true];

// // const product1 = {
// // 	0: 'iPhone',
// // 	1: 'Apple',
// // 	2: 'Some desc...',
// // 	3: 150000,
// // 	4: 100,
// // 	5: true,
// // 	length: 6,
// // };

// // let firstName = 'John';

// // let firstName = {0: 'J', 1: 'o', 2: 'h', 3: 'n', length: 4}

// const song1 = {
// 	name: 'Some name #1',
// 	artist: ['John', 'Jane'],
// 	trackLength: 3.2,
// 	album: 'Some Album',
// };

// const playlist = [
// 	{
// 		name: 'Some name #1',
// 		artist: ['John', 'Jane'],
// 		trackLength: 3.2,
// 		album: 'Some Album',
// 	},
// 	{
// 		name: 'Some name #1',
// 		artist: ['John', 'Jane'],
// 		trackLength: 3.2,
// 		album: 'Some Album',
// 	},
// ];

const pallette = {
	red: '#eb4d4b',
	yellow: '#f9ca24',
	blue: '#30336b',
};

let color = 'yellow';

console.log(pallette[color]);

Scratchpad #5

// for (let i = 0; i < 100; i += 10) {
// 	console.log(i);
// 	console.log('Hello World');
// }

// console.log('LOOP ENDS');

// for (let num = 1; num <= 10; num++) {
// 	console.log(`${num}*${num}=${num * num}`);
// }

// for (let i = 50; i >= 0; i += 5) {
// 	console.log(i);
// }

// const nums = [12, 34, 56, 34, 78, 54, 23, 12];

// let total = 0;

// for (let i = 0; i < nums.length; i++) {
// 	total += nums[i];
// }

// console.log(total);

// 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}`);
// }

// 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 += word[i];
// }

// console.log(reversedWord);

// for (let i = 0; i < 5; i++) {
// 	console.log(i);
// 	for (let j = 0; j < 5; j++) {
// 		console.log('     ' + j);
// 		for (let k = 0; k < 5; k++) {
// 			console.log('          ' + k);
// 		}
// 	}
// }

// 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++) {
// 		total += gameBoard[i][j];
// 	}
// }

// console.log(total);

// for (let i = 0; i < 10; i++) {
// 	console.log(i);
// }

// let j = 0;

// while (j < 10) {
// 	console.log(j);
// 	j++;
// }

// const target = Math.floor(Math.random() * 10) + 1;
// let guess = Math.floor(Math.random() * 10) + 1;

// while (guess !== target) {
// 	break;
// 	// if (guess === 3) {
// 	// 	console.log("3 is an unlucky number. I'm stopping.");
// 	// 	break;
// 	// }
// 	console.log(`Guess: ${guess} | Target: ${target}`);
// 	guess = Math.floor(Math.random() * 10) + 1;
// }

// console.log(`Final Result\nGuess: ${guess} | Target: ${target}`);

// const target = Math.floor(Math.random() * 10) + 1;
// let guess = Math.floor(Math.random() * 10) + 1;

// while (true) {
// 	if (guess === target) {
// 		break;
// 	}
// 	console.log(`Guess: ${guess} | Target: ${target}`);
// 	guess = Math.floor(Math.random() * 10) + 1;
// }

// console.log(`Final Result\nGuess: ${guess} | Target: ${target}`);

const nums = [12, 34, 56, 34, 78, 54, 23, 12];

// for (let i = 0; i < nums.length; i++) {
// 	console.log(nums[i]);
// }

// for (let num of nums) {
// 	console.log(num);
// }

// 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 col of row) {
// 		console.log(col);
// 	}
// }

// 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,
};

// console.log(Object.keys(productPrices));
// console.log(Object.values(productPrices));

// for (let key of Object.keys(productPrices)) {
// 	console.log(key, productPrices[key]);
// }

for (let key in productPrices) {
	console.log(key, productPrices[key]);
}

Scratchpad #6

// function greet() {
// 	console.log('Hello World');
// 	console.log('I am a machine');
// }

// greet();
// greet();
// greet();
// greet();

// for (let i = 0; i < 50; i++) {
// 	greet();
// }

// function rollDie() {
// 	const num = Math.floor(Math.random() * 6) + 1;
// 	console.log(num);
// }

// function throwDice() {
// 	rollDie();
// 	rollDie();
// 	rollDie();
// }

// throwDice();

// function greet(person, message) {
// 	// parameter <- variable
// 	console.log(`${message} ${person}`);
// }

// greet('John', 'Hello');
// greet('Jane', 'Hi');

// function add(a, b) {
// 	console.log(a + b);
// }

// add(10, 1000);

// function rollDie() {
// 	const num = Math.floor(Math.random() * 6) + 1;
// 	console.log(num);
// }

// function throwDice(times) {
// 	for (let i = 0; i < times; i++) {
// 		rollDie();
// 	}
// }

// throwDice(2);

// console.log('hello'.toUpperCase());

// function greet(person, message) {
// 	return `${message} ${person}`;
// }

// console.log(greet('John', 'Hello'));

// function checkIfNumber(value) {
// 	if (typeof value !== 'number') {
// 		return false;
// 	} else {
// 		return true;
// 	}
// }

// console.log(checkIfNumber(100));

// function hello() {
// 	let fullName = 'John Smith';
// 	console.log(fullName);
// }

// hello();

// console.log(fullName);

// let fullName = 'John Doe';

// if (true) {
// 	let fullName = 'Jane Doe';
// 	console.log(fullName);
// }

// console.log(fullName);

// for (var i = 0; i < 5; i++) {
// 	console.log(i);
// }

// console.log(i);

// function hello() {
// 	var world = 'World';
// 	console.log(world);
// }

// hello();

// console.log(world);

Scratchpad #7

// var hello;

// // // function outer() {
// // // 	// let movie = 'Avengers';

// // // 	function inner() {
// // // 		let movie = 'Iron man';
// // // 		console.log(movie);
// // // 	}

// // // 	console.log(movie);

// // // 	inner();
// // // }

// // // outer();

// // let total = 0;

// // function test(total, num) {
// // 	total += num;
// // 	return total;
// // }

// // test(total, 2);
// // test(total, 2);
// // test(total, 2);

// // function greet() {
// // 	console.log('Hello World');
// // }

// // const hello = greet;

// // let world = 100;

// // hello();

// // const greet = function () {
// // 	console.log('Hello World');
// // };

// // function math(a, b, fn) {
// // 	return fn(a, b);
// // }

// // function add(a, b) {
// // 	return a + b;
// // }

// // function sub(a, b) {
// // 	return a - b;
// // }

// // 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[2](10, 4));

// // 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 math(a, b, fn) {
// 	return fn(a, b);
// }

// 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 randomPick(f1, f2) {
// 	let randNum = Math.random();
// 	if (randNum < 0.5) {
// 		f1();
// 	} else {
// 		f2();
// 	}
// }

// randomPick(sayHello, sayGoodbye);

// function raiseBy(num) {
// 	return function (x) {
// 		return num ** x;
// 	};
// }

// const square = raiseBy(2);
// const cube = raiseBy(3);
// const hypercube = raiseBy(4);

// console.log(square(5));
// console.log(cube(5));
// console.log(hypercube2(5));

// 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, 45, add));

// setTimeout(function () {
// 	console.log('Hello World');
// }, 3000);

// setInterval(function () {
// 	console.log('Hello World');
// }, 3000);

// add(10, 5);

// // --------------FUNCTIONS----------------

// function add(a, b) {
// 	console.log(a + b);
// }

// let hello = 'world';
// console.log(hello);

let arr = [
	[
		[1, 2, 3],
		[1, 2, 3],
		[1, 2, 5],
	],
	[
		[1, 2, 3],
		[1, 2, 3],
		[1, 2, 3],
	],
	[
		[1, 2, 3],
		[1, 2, 3],
		[1, 2, 3],
	],
];

// for loop
// while loop
// for..of

// capitalize(sentence)
// capitalize("hello world, this is some text.")
// "Hello World, This Is Some Text."

// reverseStr(str)
// reverseStr("hello")
// "olleh"

// findNegatives(arr)
// findNegatives([1,123,4,-234,-12,-1,2,23])
// [-234, -12, -1]

Scratchpad #8

// // // // // // // function math(a, b, func) {
// // // // // // // 	return func(a, b);
// // // // // // // }

// // // // // // // console.log(
// // // // // // // 	math(10, 5, function (a, b) {
// // // // // // // 		return a + b;
// // // // // // // 	})
// // // // // // // );

// // // // // // const arr1 = [1, 2, 3, 4, 56, 76, 22, 2223, 435, 4523];

// // // // // // // 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} has a rating for ${movie.rating}`);
// // // // // });

// // // // // const names = ['john', 'jack', 'jane', 'james'];

// // // // // const uppercasedNames = names.map(function (name) {
// // // // // 	return name.toUpperCase();
// // // // // });

// // // // // const uppercasedNames = [];

// // // // // for (let name of names) {
// // // // // 	uppercasedNames.push(name.toUpperCase());
// // // // // }

// // // // // console.log(uppercasedNames);

// // // // 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 numDetails = nums.map(function (num) {
// // // // 	return {
// // // // 		number: num,
// // // // 		isEven: num % 2 === 0,
// // // // 	};
// // // // });

// // // // console.log(numDetails);

// // // // function add(a, b) {
// // // // 	return a + b;
// // // // }

// // // // const add2 = function (a, b) {
// // // // 	return a + b;
// // // // };

// // // // const add3 = (a, b) => {
// // // // 	return a + b;
// // // // };

// // // // console.log(add3(10, 5));

// // // // const greet = person => {
// // // // 	return `hello ${person}`
// // // // };

// // // // console.log(greet("john"));

// // // const nums = [2, 3, 4, 7, 6, 8, 13, 10, 19, 12, 14, 22, 21, 16];

// // // const doubles = nums.map(n => n * 2);

// // // console.log(doubles);

// // // const nums = [1,2,3,4,5,6]

// // // // using regular function expressions
// // // const doubles1 = nums.map(function (n) {
// // //   return n * 2
// // // })

// // // // using arrow functions
// // // const doubles2 = nums.map(n => {
// // //   return n * 2
// // // })

// // // // using arrow function's one-liner implicit return
// // // const doubles3 = nums.map(n => n * 2)
// // // const parityList = nums.map(n => n % 2 === 0 ? 'Even' : 'Odd')

// // let movies = ['The Terminator', 'The Avengers', 'Jurassic Park', 'Titanic'];

// // // let result = movies.find((movie) => {
// // // 	return movie.includes('park');
// // // });

// // // console.log(result);

// // let result = movies.find((movie) => movie[0] === 'J');
// // 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.find(b => b.rating >= 4.3)

// // const georgeBook = books.find(b => (
// //   b.author.includes('George')
// // ))

// // const lowRated = books.find(book => {
// //   return book.rating < 4
// // })

// // console.log(goodBook)
// // console.log(georgeBook)

// // let result = books.filter((book) => book.rating > 3.5);
// // 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(filteredBooks);

// const names = ['jack', 'james', 'john', 'jane', 'josh', 'jrad'];

// const result = names.every((name) => name[0] === 'j');
// console.log(result);

// const bestBooks = books.every((book) => book.rating >= 4);

// const notAuthor = books.every(
// 	(book) => book.author.toLowerCase() !== 'chetan bhagat'
// );

// console.log(bestBooks);
// console.log(notAuthor);

// const names = ['jack', 'james', 'john', 'jane', 'josh', 'jrad'];

// const result = names.some((name) => name[0] === 'b');
// console.log(result);

// const prices = [500.4, 211, 23, 5, 4, 22.2, -23.2, 9233];

// prices.sort((a, b) => b - a);
// console.log(prices);

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,
	},
];

books.sort((a, b) => a.rating - b.rating);
console.log(books);