Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This PR is the solution to the 'bank-project' #4 #28

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
50 changes: 50 additions & 0 deletions 1-js-basics/1-data-types/excercise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// let myVariable;
// myVariable has now been declared using the let keyword. It currently doesn't have a value.

let myVariable = 123;
// The above is called an explicit initialization when a variable is declared and is assigned a value at the same time.

const PI = 3;
// PI = 4; // not allowed
// Constants must be initialized, or an error will occur when running code.
// The reference of a constant cannot be changed once initialized, or an error will occur when running code.

let myString1 = "Hello";
let myString2 = "World";

myString1 + myString2 + "!"; //HelloWorld!
myString1 + " " + myString2 + "!"; //Hello World!
myString1 + ", " + myString2 + "!"; //Hello, World!
// Template literals are another way to format strings, except instead of quotes, the backtick is used. Anything that is not plain text must be placed inside placeholders ${ }. This includes any variables that may be strings.

// Challenge

// 1. Case Sensitivity
let age = 1;
let Age = 2;
console.log(age == Age); // false
// JavaScript is case-sensitive, meaning age and Age are treated as entirely different variables.

// 2. Type Coercion
console.log(1 == '1'); // true
console.log(1 === '1'); // false
// == performs type coercion, converting '1' (string) to 1 (number) before comparing.
// === is a strict equality operator and doesn't perform type coercion, so it compares both value and type.

// 3. numm vs. undefined
console.log(null == undefined); // true
console.log(null === undefined); // false

// null and undefined are considered loosely equal (==) because they both represent "absence of value".
// They are not strictly equal (===) because null is an object type and undefined is a primitive type.

// 4. NaN is Not Equal to Itself
console.log(NaN == NaN); // false
console.log(NaN === NaN); // false
// NaN (Not-a-Number) is unique in that it is not equal to anything, including itself. Use Number.isNaN(value) to check for NaN.

// 5. Typeof Difference
console.log(typeof null); // "object"
console.log(typeof NaN); // "number"
// typeof null returns "object" because of a historical bug in JavaScript that was never fixed for backward compatibility.
// typeof NaN returns "number" because NaN is technically a special value of the number type.
54 changes: 54 additions & 0 deletions 1-js-basics/1-data-types/solution1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Solution for 1: data types

Everything that I studied, that is, all the theory with the programs is metioned in the excercise_.js file
I have also attached a js file to run and check the code.

The question is quite simple. We need to mention the data types that we would need to complete a shopping experience.

The experience can be divided into 5 different parts:

## User Login detials
| Name (Property) | Data Type | Reason |
|------------------|-----------|----------------------------------------------------------------------------------------|
| `id` | String | - Unique identifier for the user. <br> - String is used as it will be a combination of letters and numbers. |
| `name` | String | - Name of Customer. <br> - String is used to store names. |
| `email` | String | - Authentication. <br> - Combination of letters, numbers, and special characters. |
| `isLoggedIn` | Boolean | - Check the status of a session. <br> - A user can be logged in or not, thus Boolean. |

---

## Product Information
| Name (Property) | Data Type | Reason |
|------------------|-----------|----------------------------------------------------------------------------------------|
| `id` | String | - Unique identifier for each product. <br> - String is used as it will be a combination of letters and numbers. |
| `name` | String | - Name of Product. <br> - String is used to store names. |
| `price` | Double | - Represents the cost of the product. <br> - Number is used to perform final cost calculations. |
| `quantity` | Integer | - Number of products available. |
| `isAvailable` | Boolean | - Checks if a product is available or not. <br> - A product can be available or not, thus Boolean. |

---

## Shopping Cart
| Name (Property) | Data Type | Reason |
|------------------|-----------|----------------------------------------------------------------------------------------|
| `items` | Array | - Holds all the products added to the cart. |
| `totalPrice` | Double | - Sum of prices will be a double. |
| `discount` | Double | - Stores discount percentage or amount. |

---

## Payment Details
| Name (Property) | Data Type | Reason |
|------------------|-----------|----------------------------------------------------------------------------------------|
| `cardNumber` | String | - Allows payment processing systems to validate it. <br> - It will be a combination of numbers and dashes. |
| `totalPaid` | Double | - Reflects the final amount after discounts. |

---

## Order Summary
| Name (Property) | Data Type | Reason |
|------------------|-----------|----------------------------------------------------------------------------------------|
| `orderId` | String | - Unique identifier for each order. |
| `items` | Array | - Lists purchased products. |
| `totalPrice` | Double | - Reflects the amount charged. |
| `deliveryDate` | String | - Displays the estimated delivery date. |
44 changes: 44 additions & 0 deletions 1-js-basics/2-functions-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// a function is a block of code we can execute on demand. This is perfect for scenarios where we need to perform the same task multiple times

// Syntax
function nameOfFunction() { // function definition
// function definition/body
}


// Whenever we want to call (or invoke) our function, we use the name of the function followed by ()

// If we want to make it a little more flexible, like allowing someone to specify the name of the person to greet, we can add a parameter. A parameter (also sometimes called an argument), is additional information sent to a function
// Syntax
function name(param, param2, param3) {

}

function displayGreeting(name) {
const message = `Hello, ${name}!`;
console.log(message);
}
displayGreeting('Prarthana');
// displays "Hello, Prarthana!" when run
// If someone doesn't want to customize it, we provide a default value instead. To provide a default value to a parameter, we set it much in the same way we set a value for a variable

function displayGreeting2(name, salutation='Hello') {
console.log(`${salutation}, ${name}`);
}
displayGreeting2('Prarthana', 'Hi');
// displays "Hi, Prarthana"

// A return value is returned by the function, and can be stored in a variable just the same as we could store a literal value such as a string or number.



// It uses a special indicator of =>, which looks like an arrow - thus the name! By using =>, we are able to skip the function keyword
// Syntax
setTimeout(() => {
console.log('3 seconds has elapsed');
}, 3000);

// Challenge

// Functions are standalone blocks of code that perform tasks, while methods are functions associated with an object and can access and modify the object's data.
// Functions are independent and can be called on their own, whereas methods are tied to objects and operate on the object's attributes.
52 changes: 52 additions & 0 deletions 1-js-basics/2-functions-methods/solution2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Solution for 2: Functions

Everything that I studied, that is, all the theory with the programs is metioned in the excercise_.js file
I have also attached a js file to run and check the code.

This assignment will familiarise you with the use of functions in different situations.

## Function that returns something:

```
function addNumbers(a, b) {
return a + b;
}

// Example usage:
const result = addNumbers(1, 2);
console.log(`Sum: ${result}`); // Output: Sum: 3


```
## Function that doesn't return anything

```
def greet_user(name):
function greetUser(name) {
console.log(`Hello, ${name}!`);
}

// Example usage:
greetUser("Prarthana"); // Output: Hello, Prarthana!


```
## Function with no Parameters

```
function printMessage() {
console.log("Dream Team Task: 04");
}
printMessage();

```
## Function with mix parameters

```
function introducePerson(name, age = 20, city = "Hyd") {
return `My name is ${name}, I am ${age} years old, and I live in ${city}.`;
}
const intro1 = introducePerson("Prarthana");
console.log(intro1);

```
114 changes: 114 additions & 0 deletions 1-js-basics/3-making-decisions/excercise3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// The if statement will run code in between its blocks if the condition is true
// Syntax

// if (condition) {
// //Condition is true. Code in this block will run.
// }

//Example:
let currentMoney = 10;
let laptopPrice = 20;

if (currentMoney >= laptopPrice) {
//Condition is true. Code in this block will run.
console.log("Getting a new laptop!");
}

// The else statement will run the code in between its blocks when the condition is false. It's optional with an if statement.
// Syntax + Example
if (currentMoney >= laptopPrice) {
//Condition is true. Code in this block will run.
console.log("Getting a new laptop!");
} else {
//Condition is false. Code in this block will run.
console.log("Can't afford a new laptop, yet!");
}

// Switch Statement
// The switch statement is used to perform different actions based on different conditions. Use the switch statement to select one of many code blocks to be executed.
// Syntax

// switch (expression) {
// case x:
// // code block
// break;
// case y:
// // code block
// break;
// default:
// // code block
//}

// program using switch statement
let a = 7;

switch (a) {
case 1:
a = "one";
break;
case 2:
a = "two";
break;
default:
a = "not found";
break;
}
console.log(`The value is ${a}`);

// Conditions and Decisions with Logical Operators
let laptopDiscountPrice = laptopPrice - laptopPrice * 0.2; //Laptop price at 20 percent off

if (currentMoney >= laptopPrice || currentMoney >= laptopDiscountPrice) {
//Condition is true. Code in this block will run.
console.log("Getting a new laptop!");
} else {
//Condition is true. Code in this block will run.
console.log("Can't afford a new laptop, yet!");
}

// Negation operator
// Anything that goes into an if needs to evaluate to true/false. By using the ! operator you can negate the expression
// Syntax
// if (!condition) {
// // runs if condition is false
// } else {
// // runs if condition is true
// }

// Ternary expressions
// Syntax
// let variable = condition ? <return this if true> : <return this if false></return>

let firstNumber = 20;
let secondNumber = 10;
let biggestNumber = firstNumber > secondNumber ? firstNumber : secondNumber;
console.log(biggestNumber);

// Challenge
function checkNumber(num) {
let result;
if (num > 0) {
result = "Positive";
} else if (num < 0) {
result = "Negative";
} else {
result = "Zero";
}
return result;
}

console.log(checkNumber(5)); // Output: Positive
console.log(checkNumber(-3)); // Output: Negative
console.log(checkNumber(0)); // Output: Zero

function checkNumber1(num) {
let result = num > 0 ? "Positive" : num < 0 ? "Negative" : "Zero";
return result;
}

// Test
console.log(checkNumber1(5)); // Output: Positive
console.log(checkNumber1(-3)); // Output: Negative
console.log(checkNumber1(0)); // Output: Zero

// I prefer If..else..if (logical operator approach) as its easily understandable and readable.
19 changes: 19 additions & 0 deletions 1-js-basics/3-making-decisions/solution3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
let allStudents = ['A', 'B-', 1, 4, 5, 2, 'C', 3, 'C-'];
let passedStudents = [];

for (let i = 0; i < allStudents.length; i++) {
let grade = allStudents[i];
if (typeof grade === 'number') {
// First grading system (numeric grades)
if (grade >= 3) {
passedStudents.push(grade);
}
} else if (typeof grade === 'string') {
// Second grading system (letter grades)
if (grade === 'A' || grade === 'A-' || grade === 'B' || grade === 'B-' || grade === 'C') {
passedStudents.push(grade);
}
}
}

console.log("Students who pass:", passedStudents);
29 changes: 29 additions & 0 deletions 1-js-basics/3-making-decisions/solution3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Solution for 3: Decision Making

Everything that I studied, that is, all the theory with the programs is metioned in the excercise_.js file
I have also attached a js file to run and check the code.

Solution for the Operators

```
let allStudents = ['A', 'B-', 1, 4, 5, 2, 'C', 3, 'C-'];
let passedStudents = [];

for (let i = 0; i < allStudents.length; i++) {
let grade = allStudents[i];
if (typeof grade === 'number') {
// First grading system (numeric grades)
if (grade >= 3) {
passedStudents.push(grade);
}
} else if (typeof grade === 'string') {
// Second grading system (letter grades)
if (grade === 'A' || grade === 'A-' || grade === 'B' || grade === 'B-' || grade === 'C') {
passedStudents.push(grade);
}
}
}

console.log("Students who pass:", passedStudents);

```
Loading