diff --git a/1-js-basics/1-data-types/solution.md b/1-js-basics/1-data-types/solution.md new file mode 100644 index 0000000..289f3dc --- /dev/null +++ b/1-js-basics/1-data-types/solution.md @@ -0,0 +1,36 @@ +

Review and Self Study

+ +```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 +``` + +

Challenge

+

+ 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 +

+ + + +

Assignment

+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
+ + +

+

+

+ diff --git a/1-js-basics/2-functions-methods/solution.md b/1-js-basics/2-functions-methods/solution.md new file mode 100644 index 0000000..db4a824 --- /dev/null +++ b/1-js-basics/2-functions-methods/solution.md @@ -0,0 +1,30 @@ +

Challenge

+

method is something that belong to an object or a class. It is also defined within a class defination.
+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 +

+ + + + +

assignment

+ +```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); +} +``` + diff --git a/1-js-basics/3-making-decisions/solution.md b/1-js-basics/3-making-decisions/solution.md new file mode 100644 index 0000000..6440ce0 --- /dev/null +++ b/1-js-basics/3-making-decisions/solution.md @@ -0,0 +1,25 @@ +

Challenge

+ +```javascript +if(x>5){ + print(x) +}else{ + print("no") +} +``` +with ternery operator, + +```javascript +let var = (x>5)? print(5) : print("no") +``` + +

Assignment

+ +```javascript +studentsWhoPass=[]; +for(let i=0, i<6, i++){ + if !(allStudents[i]=="C-" || allStudents[i]==2 || allStudents[i]==1){ + studentsWhoPass.push(allStudents[i]); + } +} + diff --git a/1-js-basics/4-arrays-loops/solution.md b/1-js-basics/4-arrays-loops/solution.md new file mode 100644 index 0000000..3354659 --- /dev/null +++ b/1-js-basics/4-arrays-loops/solution.md @@ -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);} +} +``` + + + + +