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

Completed solution for issue 1 #56

Open
wants to merge 1 commit 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
58 changes: 58 additions & 0 deletions 1-js-basics/1-data-types/SOLUTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Data Types in a Shopping Cart

## Introduction
A shopping cart contains different data types to effectively manage UI, products, user and network. Here are some of the data types that may be useful for developing a shopping cart:

## Data Types

### 1. **String**
**Purpose:** To store data like user name, product name, locations etc...
**Example:**
```javascript
let userName = "Gokul";
let productName = "Pavillion HP Gaming Laptop"
```

### 2. **Array**
**Purpose:** To store different product objects in a cart, listing all products in the document
**Example:**
```javascript
let productList = [];
productList.push(myProduct);
```

### 3. **Boolean**
**Purpose:** To store values that represent true or false like the availability of product, user is logged in, free shipping etc...
**Example:**
```javascript
bool isAvailable = false;
if(!isAvailable)
{
...
}
```

### 4. **Date**
**Purpose:** Date type can be used to display the delivery date, packaging date etc...
**Example:**
```javascript
const delivery = new Date("2025-03-10");
```

### 5. **Object**
**Purpose:** Object can be an instance of a Product class, which may contain information about count, price etc... An array of product objects are added to the cart.
**Example:**
```javascript
let product = new Product("Kurti", 299.9);
```

## Challenge

```javascript
NaN == NaN // false
Number.isNaN(NaN) // true

## Assignment
```
<input type="button" value="Go Back From Whence You Came!" onclick="history.back(-1)" />
```
40 changes: 40 additions & 0 deletions 1-js-basics/2-functions-methods/SOLUTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## Challenge
Functions and methods are very similar but they differ in OOP. Functions defined in a class is known as methods. Functions are independent of any class.


## Assignment
```javascript
function say() {
console.log("Hello world!");
}

say();
```

```javascript
function greet(name = "User") {
console.log("Hello " + name + "!");
}

greet("Nandu");
```

```javascript

function isOdd(n) {
return n & 1;
}

if (isOdd(5)) {
console.log("5 is an odd number!");
} else {
console.log("5 is an even number!");
}
```

```javascript
function sum(...numbers) {
return numbers.reduce((acc, num) => acc + num, 0);
}
console.log(sum(5, 6, 2, 3))
```
44 changes: 44 additions & 0 deletions 1-js-basics/3-making-decisions/SOLUTION.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
## Challenge

```javascript
x = 10
if (x%5 == 0) {
console.log("Divisible by 5");
} else {
console.log("Not divisible by 5");
}
```

```javascript
x = 8
console.log(x%5 == 0 ? "Divisible by 5" : "Not divisible by 5");
```

I prefer using if else statements for understandability and I use ternary operator when the program code does not look good.

## Assignment

```javascript
let allStudents = [
'A',
'B-',
1,
4,
5,
2
]

let studentsWhoPass = [];

allStudents.forEach(v => {
if (typeof(v) == 'string') {
if (v != 'C-') {
studentsWhoPass.push(v)
}
} else {
if (v>3) {
studentsWhoPass.push(v)
}
}
});
```
36 changes: 36 additions & 0 deletions 1-js-basics/4-arrays-loops/SOLUTION.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## Challenge ##

```javascript

let numbers = [1, 2, 3, 4]

// Normal for loop

for (let i = 0; i < numbers.length; i++) {
console.log(numbers[i] * 2);
}

// for each

numbers.forEach(num => console.log(num*2));

// map

console.log(numbers.map(num => num*2));

// for of

for(let num in numbers) {
console.log(num*2);
}
```

## Assignment ##

```javascript

for(let i=1; i<=20; i++) {
if (i%3 == 0) {
console.log(i);
}
}