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 'js basics' #1 #38

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
solved issues
Mihir205 committed Dec 6, 2024
commit 6b1dc9209f713be27c3c7b7053121786fd5b3ae4
103 changes: 103 additions & 0 deletions 1-js-basics/solution.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# JavaScript Basics
## Subtopic 1: Data Types

### Assignment

Create a product object with the following properties and corresponding data types:
- **Product Name**: String
- **Product ID**: String
- **Price**: Float
- **Quantity**: Float
- **Product Availability**: Boolean
- **Product Category**: Enumerator (use an `enum` or similar structure to define categories such as "Electronics", "Clothing", etc.).


### Challenge

Evaluate the following code snippets and understand the difference between `==` and `===`:

```javascript
console.log(12 == '12'); // Output: true
console.log(12 === '12'); // Output: false
```
---

## Subtopic-2: Methods and Functions

### Assignment:
```
function sum(x,y){
console.log(x+y);
}
sum(5,3);
```

```
function sum(){
let a = 2;
let b = 3;
console.log(a+b);
}
sum()
```
```
function sum(a,b=1,c=3){
console.log(a+b+c);
}
sum(2);
sum(2,3,4);
```
### Challenge:
The difference between function and method is that a method is associated with object whereas function is not associated with object and can take input argument.

---

## Subtopic-3: Making Decisions
### Assignment:
```
let allStudents = ['A','B-',1,4,5,2];
let studentsWhoPass = [];
for (let i = 0; i < allStudents.length; i++) {
let grade = allStudents[i];
if (typeof grade === 'number' && grade >= 3) {
studentsWhoPass.push(grade);
}
else if (typeof grade === 'string' && (grade === 'A' || grade === 'A-' || grade === 'B' || grade === 'B-' || grade === 'C')){
studentsWhoPass.push(grade);
}
}
```

### Challenge:
```
let a=10;
if (a%2==0 && a%3==0){
console.log("Divisble by 6");
}
else{
console.log("Not divisble by 6");
}
```
or
```
console.log(a%2==0 && a%3==0 ? "Divisible by 6" : "Not divisible by 6");
```

---

## Subtopic-4: Array-Loops
### Assignment:
```
for(let i=3;i<20;i+=3){
console.log(i);
}
```

### Challenge:
Using for-of
```
let a=[1,2,3,4,5];
for(let i of a){
console.log(i);
}
```
101 changes: 101 additions & 0 deletions 2-terrarium/solution.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# My Terrarium
## Subtopic 1: Intro to HTML

### Assignment
```
<marquee>
<h1>My terrarium</h1>
</marquee>
```
### Challenge
```
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Website</title>
</head>
<body>
<h1>Info about me</h1>
<div id="info">
<div class="holder">
<p class="tag">Name</p>
<p class="vaule">P.Mihir</p>
</div>
<div class="holder">
<p class="tag">Bday/p>
<p class="value">02-09-2005</p>
</div>
<div class="holder">
<p class="tag">Gender</p>
<p class="value">Male</p>
</div>
<div class="holder">
<p class="tag">Address</p>
<p class="value">Narsapur,W.G District,A.P</p>
</div>
<h2>Education</h2>
<div class="holder">
<p class="tag">College</p>
<p class="value">Amrita</p>
</div>
<div class="holder">
<p class="tag">Branch</p>
<p class="value">CSE</p>
</div>
<div class="holder">
<p class="tag">Semisterr</p>
<p class="value">3</p>
</div>
</div>
</body>
</html>
```
---

## Subtopic-2: Intro to CSS
## Assignment
![image](https://github.com/user-attachments/assets/4e0672d3-a5a1-459a-9e2d-7b985df4a5d7)

## Challenge
```
.jar-glossy-long{
width: 4%;
height: 25%;
background:#eee;
border-radius: 1rem;
position: absolute;
bottom: 18%;
left: 5%;
}
.jar-glossy-short{
width: 4%;
height: 7%;
background: white;
border-radius: 1rem;
position: absolute;
bottom: 48%;
left: 5%;
}
```
---

## Subtopic-3: Intro to DOM and Closures
## ASsignment
Event Interface (DOM Element)
Event Interfae is one of the central part of DOM and it represents an event that takes place on event target. It can be triggered by clicking the mouse button, keys on the keyboard, or network change.
we might find that event used in most of websites for capturing and responding to user interactions. It is also commonly used in our daily tasks of designing and developing websites.

A classic example of where Event interface is used is in Google's Homepage. When you start searching for something the 'input' Event triggers and it will start showing some suggestion regarding the search content.

## Challenge
```
terrariumElement.addEventListener("dblclick", (event) => {
let highlightColor = "#FFD700";
terrariumElement.style.border = "solid black 2px";
terrariumElement.style.maxWidth = "85%";
terrariumElement.style.background = highlightColor;
});
}
```
Loading