Skip to content

Js basics #78

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

Open
wants to merge 3 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
36 changes: 36 additions & 0 deletions 1-js-basics/1-data-types/solution.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<h1> Review and Self Study</h1>

```javascript
const arr = ["hi",how"","you"];
const first = arr.pop();
console.log(first); // this will not only remove last element but it also returns that last element
const last = arr.shift();
console.log(last); // same goes for this too it not only removes first element but also reeturns it

```
```javascript
const arr = ["hi","how","you"];
const first = arr.slice(0, 1);// first will store hi
const rem = arr.slice(1); // rem will store how and you
```

<h1>Challenge</h1>
<p>
since age points 1 and Age points 2, age==Age returns false. other than this, using === compares not only values but also its data types
</p>



<h1>Assignment</h1>
When we are building a shopping cart, we need many things which include user name, his password, an array of all items which contain objects which probably include a name of item and number of such items<br>


<p>
<ul>
<li>username - username is stored in a String</li>
<li>password - it might be an alpha-numeric one. so its string</li>
<li>cart-items - an array of all items in the cart</li>
<li>a list of objects where each object can store a name and a value where value is number of items of that type</li>
</ul>
</p>

30 changes: 30 additions & 0 deletions 1-js-basics/2-functions-methods/solution.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<h1> Challenge</h1>
<p>method is something that belong to an object or a class. It is also defined within a class defination. <br>
while function is something that can be defined any where and used anywhere. A method can only be used to manipulate or something related to it to a class or its objects
</p>




<h1>assignment</h1>

```javascript
function funct1(a){
console.log(a);
}
```
or it can be written the following way

```javascript
function funct2(a){
return a;
}
```
here is a function with default and normal parameters

```javascript
function funct3( a =2 , b){
console.log(a+b);
}
```

25 changes: 25 additions & 0 deletions 1-js-basics/3-making-decisions/solution.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<h1> Challenge </h1>

```javascript
if(x>5){
print(x)
}else{
print("no")
}
```
with ternery operator,

```javascript
let var = (x>5)? print(5) : print("no")
```

<h1> Assignment</h1>

```javascript
studentsWhoPass=[];
for(let i=0, i<6, i++){
if !(allStudents[i]=="C-" || allStudents[i]==2 || allStudents[i]==1){
studentsWhoPass.push(allStudents[i]);
}
}

32 changes: 32 additions & 0 deletions 1-js-basics/4-arrays-loops/solution.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Review & Self Study


```javascript
const items = ["item1", "item2", "item3"];
const copyItems = [];

for (let i = 0; i < items.length; i++) {
copyItems.push(items[i]);
}

items.forEach((item) => {
copyItems.push(item);
});
```
# Challenge
```javascript
array=[1,2,3,4]
array.forEach((element) => console.log(element));
```

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