From 41ceacb24d36de299c1c4f18745d4b18aa4dd027 Mon Sep 17 00:00:00 2001 From: jamesjose03 Date: Sat, 19 Oct 2019 17:17:03 +0530 Subject: [PATCH 1/5] feat: Addition of tasks 13-15 --- src/workspace/js/solutions/task13.js | 6 ++++++ src/workspace/js/solutions/task14.js | 20 ++++++++++++++++++++ src/workspace/js/solutions/task15.js | 8 ++++++++ src/workspace/js/tasks.json | 17 ++++++++++++++++- 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/workspace/js/solutions/task13.js create mode 100644 src/workspace/js/solutions/task14.js create mode 100644 src/workspace/js/solutions/task15.js diff --git a/src/workspace/js/solutions/task13.js b/src/workspace/js/solutions/task13.js new file mode 100644 index 0000000..ae1c149 --- /dev/null +++ b/src/workspace/js/solutions/task13.js @@ -0,0 +1,6 @@ +let no = [45,23,767,921] + +for(i=0;i23) + console.log(no[i]) +} \ No newline at end of file diff --git a/src/workspace/js/solutions/task14.js b/src/workspace/js/solutions/task14.js new file mode 100644 index 0000000..d42955c --- /dev/null +++ b/src/workspace/js/solutions/task14.js @@ -0,0 +1,20 @@ +let a = ['ABC', 'GHI', 'DEF', 'JKL'] +let b = [1,2,3] +a.pop() +console.log(a) +a.push('PQR') +console.log(a) +a.shift() +console.log(a) +a.splice(1,2,"WER","ERT") +console.log(a) +a = a.concat(b) +console.log(a) +a.sort() +console.log(a) +a.reverse() +console.log(a) +let c = b.map((element)=> { + return 2*element +}) +console.log(c) \ No newline at end of file diff --git a/src/workspace/js/solutions/task15.js b/src/workspace/js/solutions/task15.js new file mode 100644 index 0000000..8de0c56 --- /dev/null +++ b/src/workspace/js/solutions/task15.js @@ -0,0 +1,8 @@ +let person = { + age: 75, + gender: "female" +} + +let yyyy = 2019-person.age +console.log(yyyy) +console.log(person.gender) \ No newline at end of file diff --git a/src/workspace/js/tasks.json b/src/workspace/js/tasks.json index 981ce2e..c7db4df 100644 --- a/src/workspace/js/tasks.json +++ b/src/workspace/js/tasks.json @@ -57,5 +57,20 @@ { "task": "Keep up the good work! The next topic we will cover is functions. Functions are sections of code that execute other code and make it reusable. \nIn ES6 there are 2 main ways to declare a function, the function keyword and arrow functions.\n Syntax: function name(params) {\n code\n} \nTask 12: Declare a function using the respective keyword that when given 2 numbers will add them together, then print out the result. The number pairs you need to test are 1+2, 10+15, 100+400", "op": "/solutions/task12.js" - } + }, + + { + "task": "Fantastic! Now let's move on to arrays. \n Arrays are used to store multiple values in a single variable. It can be thought of as a collection of things of the same type. Like, a collection of roll numbers. \n Arrays are declared using []. Eg: let rollno = [1,2,3] \n Here's your task: \n Task 13 \n Store the values 45,23,767,921 into an array and print the values of the array which are greater than 23. Use arrayname.length to get the length of the array.", + "op": "/solutions/task13.js" + }, + + { + "task": "Now, let's move on to array methods. \n Arrays have a variety of methods which is of a lot of help in day-to-day tasks. \n Let's get to know them: 1. pop() - Used to remove the last item from the array. \n 2. push() - Used to insert an element to the end of the array. \n 3. shift() - Used to remove the first item from the array. \n 4. splice() - Used to replace the old elements with new elements to the array. \n 5. concat() - to merge two arrays. \n 6. sort() - to sort an array \n 7. reverse() - to reverse an array. \n 8. map() - creates a new array by performing a function on each element. \n Phew! That's a lot of methods. Let's now work with each of them with the help of this task. \n Task 14 \n Create an array with the values ABC, GHI, DEF and JKL. Do the following. 1. Remove JKL from the array.\n 2. Insert PQR into the array. \n 3. Remove ABC from the array. \n 4. Replace the values DEF and PQR with WER and ERT \n 5. Create another array with values 1,2,3 and merge it with the current array. \n 6. Sort the array. \n 7. Reverse the order of elements of the array. \n 8. Create another array with elements of the second array with elements doubled and print the newly created array. \n Print the output in every case.", + "op":"/solutions/task14.js" + }, + + { + "task": "Fantastic! Let's now move on to objects. \n Objects are similar to variables except that they can take multiple values at a time. The values are written as name:value pairs. \n For eg: var car = {type:'Fiat', model:'500', color:'white'} \n Here's your task: \n Task 15 \n Create an object person with age: 75 and gender: female. Print the year of birth with the help of her age along with her gender.", + "op":"/solutions/task15.js" + }, ] From c3fea6e66f0bf0a1a6d18d89b1ac1bd14ab75434 Mon Sep 17 00:00:00 2001 From: jamesjose03 Date: Sun, 20 Oct 2019 23:28:59 +0530 Subject: [PATCH 2/5] feat: Addition of tasks 16-18 --- src/workspace/js/solutions/task16.js | 5 +++++ src/workspace/js/solutions/task17.js | 23 +++++++++++++++++++++++ src/workspace/js/solutions/task18.js | 8 ++++++++ src/workspace/js/tasks.json | 15 +++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 src/workspace/js/solutions/task16.js create mode 100644 src/workspace/js/solutions/task17.js create mode 100644 src/workspace/js/solutions/task18.js diff --git a/src/workspace/js/solutions/task16.js b/src/workspace/js/solutions/task16.js new file mode 100644 index 0000000..db53897 --- /dev/null +++ b/src/workspace/js/solutions/task16.js @@ -0,0 +1,5 @@ +console.log(Math.round(5.57)) +console.log(Math.pow(6,3)) +console.log(Math.sqrt(841)) +console.log(Math.ceil(5.3)) +console.log(Math.floor(5.3)) \ No newline at end of file diff --git a/src/workspace/js/solutions/task17.js b/src/workspace/js/solutions/task17.js new file mode 100644 index 0000000..edfd647 --- /dev/null +++ b/src/workspace/js/solutions/task17.js @@ -0,0 +1,23 @@ +switch (new Date().getDay()) { + case 0: + day = "Sunday"; + break; + case 1: + day = "Monday"; + break; + case 2: + day = "Tuesday"; + break; + case 3: + day = "Wednesday"; + break; + case 4: + day = "Thursday"; + break; + case 5: + day = "Friday"; + break; + case 6: + day = "Saturday"; + } + console.log(day) \ No newline at end of file diff --git a/src/workspace/js/solutions/task18.js b/src/workspace/js/solutions/task18.js new file mode 100644 index 0000000..35b8bd3 --- /dev/null +++ b/src/workspace/js/solutions/task18.js @@ -0,0 +1,8 @@ +let a = true.toString(); +let b = false.toString(); +console.log(typeof a) +console.log(typeof b) +let c = true +let d = false +console.log(typeof c) +console.log(typeof d) \ No newline at end of file diff --git a/src/workspace/js/tasks.json b/src/workspace/js/tasks.json index c7db4df..1a6054b 100644 --- a/src/workspace/js/tasks.json +++ b/src/workspace/js/tasks.json @@ -73,4 +73,19 @@ "task": "Fantastic! Let's now move on to objects. \n Objects are similar to variables except that they can take multiple values at a time. The values are written as name:value pairs. \n For eg: var car = {type:'Fiat', model:'500', color:'white'} \n Here's your task: \n Task 15 \n Create an object person with age: 75 and gender: female. Print the year of birth with the help of her age along with her gender.", "op":"/solutions/task15.js" }, + + { + "task": "Now's let's learn about another object called the Math object. It allows you to perform mathematical operations. \n 1. Math.round() - Returns the nearest integer value by rounding off. \n 2. Math.pow(x,y) - Returns the power of x to the value y. \n 3. Math.sqrt() - Returns the square root. \n 4. Math.random() - Returns a random value between 0 and 1. \n 5. Math.ceil() - Returns the value rounded up to the nearest integer. \n 6. Math.floor() - Returns the value rounded down to the nearest integer. \n Here's your task: \n Task 16 \n 1. Print the rounded value of 5.57. \n 2. Find the value of 6^3 and print it. \n 3. Find the square root of 841. \n 4. Print the rounded up value of 5.3 \n 5. Print the rounded down value of 5.3", + "op":"/solutions/task16.js" + }, + + { + "task":"Awesome! Let's now move on to switch statement. The switch statement is used to perform different operations based on different inputs. \n Syntax: \n switch(variable) { \n case 1: \n do something \n break; \n case 2: \n do something else \n break; .... \n default: \n Print invalid choice \n} \n Here's your task: \n Task 17 \n Receive the current day as a number using the Date.getDay() which returns the values 0-6 (0 - Sunday, 1 - Monday, etc). Based on the value received, print the day on the basis of the value returned. Use switch statement.", + "op":"/solutions/task17.js" + }, + + { + "task":"Impressive! Let's now move on to Type Conversion. \n Variables can be converted to other datatypes using the in-built function or is converted automatically by JS. \n Here's your task: \n Task 18 \n Convert the boolean values true and false to string and print their type using the typeof function. Now store true and false in other variables and print their type. Note the difference in types.", + "op":"/solutions/task18.js" + } ] From 64a7be5ca9bc831f1fec369e64fec1f448f3cdf3 Mon Sep 17 00:00:00 2001 From: James Kaviyil Jose Date: Tue, 22 Oct 2019 23:36:28 +0530 Subject: [PATCH 3/5] feat: Addition of Tasks 19-25 --- src/workspace/js/solutions/task19.js | 8 +++++++ src/workspace/js/solutions/task20.js | 5 ++++ src/workspace/js/solutions/task21.js | 9 +++++++ src/workspace/js/solutions/task22.js | 3 +++ src/workspace/js/solutions/task23.js | 7 ++++++ src/workspace/js/solutions/task24.js | 10 ++++++++ src/workspace/js/solutions/task25.js | 1 + src/workspace/js/tasks.json | 36 ++++++++++++++++++++++++++++ 8 files changed, 79 insertions(+) create mode 100644 src/workspace/js/solutions/task19.js create mode 100644 src/workspace/js/solutions/task20.js create mode 100644 src/workspace/js/solutions/task21.js create mode 100644 src/workspace/js/solutions/task22.js create mode 100644 src/workspace/js/solutions/task23.js create mode 100644 src/workspace/js/solutions/task24.js create mode 100644 src/workspace/js/solutions/task25.js diff --git a/src/workspace/js/solutions/task19.js b/src/workspace/js/solutions/task19.js new file mode 100644 index 0000000..e58ddc2 --- /dev/null +++ b/src/workspace/js/solutions/task19.js @@ -0,0 +1,8 @@ +let a = 10 +function abc(){ + let a = 4 + console.log(a) +} + +abc() +console.log(a) \ No newline at end of file diff --git a/src/workspace/js/solutions/task20.js b/src/workspace/js/solutions/task20.js new file mode 100644 index 0000000..a210ecc --- /dev/null +++ b/src/workspace/js/solutions/task20.js @@ -0,0 +1,5 @@ +const pounds = [11.21, 19.21, 46.21]; + +const sum = pounds.reduce((total, amount) => total + amount); + +console.log(sum); \ No newline at end of file diff --git a/src/workspace/js/solutions/task21.js b/src/workspace/js/solutions/task21.js new file mode 100644 index 0000000..fb68b7d --- /dev/null +++ b/src/workspace/js/solutions/task21.js @@ -0,0 +1,9 @@ +const numbers = [1, 3, 4, 6, 8, 9]; + +const filterValues = () => { + return numbers.filter(number => { + return number % 2 == 0; + }); +} + +console.log(filterValues()); \ No newline at end of file diff --git a/src/workspace/js/solutions/task22.js b/src/workspace/js/solutions/task22.js new file mode 100644 index 0000000..ed48c3b --- /dev/null +++ b/src/workspace/js/solutions/task22.js @@ -0,0 +1,3 @@ +let a = [3,9,12,15,18] +console.log(a.indexOf(15,2)) +console.log(a.indexOf(14,1)) \ No newline at end of file diff --git a/src/workspace/js/solutions/task23.js b/src/workspace/js/solutions/task23.js new file mode 100644 index 0000000..8c86e38 --- /dev/null +++ b/src/workspace/js/solutions/task23.js @@ -0,0 +1,7 @@ +let obj = { + name: 'ABC', + education: 'CSE' +} +console.log(Object.keys(obj)) +let arr = ['A','B', 'C'] +console.log(Object.keys(arr)) diff --git a/src/workspace/js/solutions/task24.js b/src/workspace/js/solutions/task24.js new file mode 100644 index 0000000..5d4a83b --- /dev/null +++ b/src/workspace/js/solutions/task24.js @@ -0,0 +1,10 @@ +let text = '{ "name":"John", "age":"39", "city":"New York"}'; +let obj = JSON.parse(text, function (key, value) { + if (key == "city") { + return value.toUpperCase(); + } else { + return value; + } +}); + +console.log(obj) \ No newline at end of file diff --git a/src/workspace/js/solutions/task25.js b/src/workspace/js/solutions/task25.js new file mode 100644 index 0000000..7404e80 --- /dev/null +++ b/src/workspace/js/solutions/task25.js @@ -0,0 +1 @@ +console.log(JSON.stringify({x:5, y:6})) \ No newline at end of file diff --git a/src/workspace/js/tasks.json b/src/workspace/js/tasks.json index 1a6054b..e7a243e 100644 --- a/src/workspace/js/tasks.json +++ b/src/workspace/js/tasks.json @@ -87,5 +87,41 @@ { "task":"Impressive! Let's now move on to Type Conversion. \n Variables can be converted to other datatypes using the in-built function or is converted automatically by JS. \n Here's your task: \n Task 18 \n Convert the boolean values true and false to string and print their type using the typeof function. Now store true and false in other variables and print their type. Note the difference in types.", "op":"/solutions/task18.js" + }, + + { + "task": "Awesome! Let's understand scope of a variable. \n Scopes define the value of the variable according to which it is defined. It can be of global or local scope.\n Global scope means that the variable can be accessed from any block of the program. Local scope means that the variable can only be accessed by the block in which it is declared in. \n To illustrate this, let's do the next task. \n Task 19 \n Declare a variable inside a function and set a value 4 to it and print it inside the function. Declare the variable with the same name outside the function block with the value 10 and print it there. \n Note the different values of the same variable printed based on its scope.", + "op":"/solutions/task19.js" + }, + + { + "task": "Now, let's move on to Javascript reduce method. \n The reduce() is used to apply a function to each element in the array to reduce the array to a single value. \n Let's now find the sum of elements of an array without using the loops. This can be done using the reduce() method. \n Syntax: array.reduce(function(total, currentValue, currentIndex, arr), initialValue) \n Here's your task: \n Task 20 \n Find the sum of elements of an array with values 11.21, 19.21, 46.21. Do not use any loops. Use reduce().", + "op":"/solutions/task20.js" + }, + + { + "task": "Fantastic! Let's now move on to Javascript filter() method. \n The name itself describes it's purpose. It is used to filter elements of the array according to a particular condition. \n Syntax: let newArray = array.filter(function(item) { \n return condition;\n });\n Task 21 \n Use the filter() to find the values of the array containing values 1,3,4,6,8,9 that are divisible by 3 and print the values as output. Do not use any loops or if statements to find the solution. Use filter function only.", + "op":"/solutions/task21.js" + }, + + { + "task": "Impressive! Let's move on to some other array method, the indexOf() method. \n This method searches for the given element from the given starting index and returns the index of the element if found or -1 if not found. \n Syntax: array.indexOf(item, start) \n Here's your task: \n Task 22 \n Store values 3,9,12,15,18 into an array and search for the element 15 starting from index 2 and then print its index. Then search for 14 starting from index 1 and print the value returned.", + "op":"/solutions/task22.js" + }, + + { + "task": "Great work! Let's now learn about keys() method. This is used for returning properties of an object or an array. \n This method returns values that are keys of the key value pair stored. \n Syntax: Object.keys(obj) \n Here's your task: \n Task 23 \n Create an object with key-value pairs \n name: 'ABC', education: 'CSE' and print the values of the keys of the object. \n Also define an array with values A,B,C. Use keys() to obtain the properties of that array and print them.", + "op":"/solutions/task23.js" + }, + + { + "task": "Now let's move on to JSON methods. The first one is JSON.parse(). It is used to parse a string written in JSON format and return a JavaScript object. \n Syntax: JSON.parse(string, function) \n Here's your task: \n Task 24 \n Create a JSON object\n var text = '{ 'name':'John', 'age':'39', 'city':'New York'}';\n Use the parse() to replace the value of city with Capital Case.", + "op": "/solutions/task24.js" + }, + + { + "task": "Great! The second one is JSON.stringify(). This method is used to convert JS Objects into strings. \n Syntax: JSON.stringify(obj, replacer, space) \n Here's your task: \n Task 25 \n Create an object {x: 5, y: 6} and convert it into a string using stringify() and print the returned value.", + "op": "/solutions/task25.js" } + ] From 35355fc2c22e505ae6e52097e0ef3678dfb18218 Mon Sep 17 00:00:00 2001 From: James Kaviyil Jose Date: Wed, 23 Oct 2019 11:51:41 +0530 Subject: [PATCH 4/5] feat: addition of Tasks 26-30 --- src/workspace/js/solutions/task26.js | 3 +++ src/workspace/js/solutions/task27.js | 9 +++++++++ src/workspace/js/solutions/task28.js | 6 ++++++ src/workspace/js/solutions/task29.js | 6 ++++++ src/workspace/js/solutions/task30.js | 10 ++++++++++ src/workspace/js/tasks.json | 27 ++++++++++++++++++++++++++- 6 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 src/workspace/js/solutions/task26.js create mode 100644 src/workspace/js/solutions/task27.js create mode 100644 src/workspace/js/solutions/task28.js create mode 100644 src/workspace/js/solutions/task29.js create mode 100644 src/workspace/js/solutions/task30.js diff --git a/src/workspace/js/solutions/task26.js b/src/workspace/js/solutions/task26.js new file mode 100644 index 0000000..0dfcd90 --- /dev/null +++ b/src/workspace/js/solutions/task26.js @@ -0,0 +1,3 @@ +let goals = ['Mission', 'Vision', 'Dedication'] +console.log(goals.includes('Mission')) +console.log(goals.includes('Success')) diff --git a/src/workspace/js/solutions/task27.js b/src/workspace/js/solutions/task27.js new file mode 100644 index 0000000..c9a6bc8 --- /dev/null +++ b/src/workspace/js/solutions/task27.js @@ -0,0 +1,9 @@ +const array1 = ['abc', 'bcd', 'cde']; + +array1.forEach(item => console.log(item)) +for (const element of array1) { + console.log(element); +} +for (const index in array1) { + console.log(index); +} diff --git a/src/workspace/js/solutions/task28.js b/src/workspace/js/solutions/task28.js new file mode 100644 index 0000000..3c1c28f --- /dev/null +++ b/src/workspace/js/solutions/task28.js @@ -0,0 +1,6 @@ +let str = 'JS is AWESOME!' +let arr = str.split(" "); +console.log(arr) +let a = ['I', 'love', 'JS!'] +let s = a.join(" ") +console.log(s) \ No newline at end of file diff --git a/src/workspace/js/solutions/task29.js b/src/workspace/js/solutions/task29.js new file mode 100644 index 0000000..08b461c --- /dev/null +++ b/src/workspace/js/solutions/task29.js @@ -0,0 +1,6 @@ +let str = 'Hello, I am a novice JS Developer.' +console.log(str.startsWith('Hello')) +console.log(str.endsWith('Develop')) +let str1 = 'I am a Polyglot' +console.log(str1.substr(str1.indexOf('P'), str1.indexOf('t'))) +console.log(str1.substring(str1.indexOf('a'), str1.indexOf('t')+1)) \ No newline at end of file diff --git a/src/workspace/js/solutions/task30.js b/src/workspace/js/solutions/task30.js new file mode 100644 index 0000000..2d16a02 --- /dev/null +++ b/src/workspace/js/solutions/task30.js @@ -0,0 +1,10 @@ +let counter = 0; + +const startCounter = () => { + counter++; + process.stdout.write(`${counter} `); +}; + +const interval = setInterval(startCounter, 1000); + +setTimeout(() => clearInterval(interval), 6000); \ No newline at end of file diff --git a/src/workspace/js/tasks.json b/src/workspace/js/tasks.json index e7a243e..2394918 100644 --- a/src/workspace/js/tasks.json +++ b/src/workspace/js/tasks.json @@ -122,6 +122,31 @@ { "task": "Great! The second one is JSON.stringify(). This method is used to convert JS Objects into strings. \n Syntax: JSON.stringify(obj, replacer, space) \n Here's your task: \n Task 25 \n Create an object {x: 5, y: 6} and convert it into a string using stringify() and print the returned value.", "op": "/solutions/task25.js" - } + }, + + { + "task": "Awesome! Let's now move on to includes() method. This is used to check whether if an element is present in an array or a string. \n Task 26 \n Create an array with elements Mission, Vision, & Dedication. Search the array for the elements Mission & Success. Print the value returned. Note that it is CASE SENSITIVE.", + "op": "/solutions/task26.js" + }, + + { + "task": "Fantastic! Here are some extras! Let's learn for of loop & foreach loop. \n We had learned for in loop before.\n foreach is an method that is available only in Array objects. It allows you to iterate through elements of an array. \n for of is a new way for iterating collections. Its introduced in ES6.\n For for of to work on an collection, the collection must have an [Symbol.iterator] property.\n Here's your task: \n Task 27 \n Create an array with elements abc,bcd,def. Loop through it using foreach, for of, for in loops. \n Note the difference in output.", + "op": "/solutions/task27.js" + }, + + { + "task": "Amazing! Let's now move on to split() and join() methods. \n split() is used to split the string into an array by specifying a delimiter. \n join() is used to join the array elements into a string based on a delimiter. \n Here's your task: \n Task 28 \n Create a variable with the string JS is AWESOME! and split it on the basis of blank spaces. \n Print the splitted array elements. \n Then create another array with element , I, love, JS! and convert it into a string and print it.", + "op":"/solutions/task28.js" + }, + + { + "task": "Great! Let's now move on to some more String Manipulation methods. \n startsWith(), endsWith(), substring(), substr()\n startsWith is used to check whether the string starts with a particular substring or not \n endsWith is used to check whether the string ends with a particular substring or not. \n substring is used to extract a particular part of a string. \n substr is also used to extract a particular part of the string except that it prints including the end index element. \n Here's your task: \n Task 29 \n Initialize a variable with the string Hello, I am a novice JS Developer. and check whether the string starts with Hello and whether it ends with Develop. Print the output. Then initialize another string with the value I am a Polyglot and extract the word Polyglot and print it. Then extract - am a Polyglot and print it. Use substring() and substr() to obtain the output.", + "op":"/solutions/task29.js" + }, + + { + "task": "Congrats! You have made it to the last task! \n Here's the task: \n Task 30 \n Use setInterval(), clearInterval(), and setTimeout() to print the values 1 to 5 with an interval from 1000 to 6000.", + "op":"/solutions/task30.js" + } ] From 4905c99f0c7c61a4afa5a6990cc1ce9dc49ec641 Mon Sep 17 00:00:00 2001 From: James Kaviyil Jose Date: Wed, 23 Oct 2019 11:59:04 +0530 Subject: [PATCH 5/5] fix: lint --- package-lock.json | 13 +++++--- src/workspace/js/solutions/task13.js | 9 +++--- src/workspace/js/solutions/task14.js | 40 ++++++++++++------------- src/workspace/js/solutions/task15.js | 12 ++++---- src/workspace/js/solutions/task16.js | 10 +++---- src/workspace/js/solutions/task17.js | 45 ++++++++++++++-------------- src/workspace/js/solutions/task18.js | 14 ++++----- src/workspace/js/solutions/task19.js | 12 ++++---- src/workspace/js/solutions/task20.js | 4 +-- src/workspace/js/solutions/task21.js | 6 ++-- src/workspace/js/solutions/task22.js | 6 ++-- src/workspace/js/solutions/task23.js | 12 ++++---- src/workspace/js/solutions/task24.js | 6 ++-- src/workspace/js/solutions/task25.js | 2 +- src/workspace/js/solutions/task26.js | 6 ++-- src/workspace/js/solutions/task27.js | 4 +-- src/workspace/js/solutions/task28.js | 12 ++++---- src/workspace/js/solutions/task29.js | 12 ++++---- src/workspace/js/solutions/task30.js | 6 ++-- 19 files changed, 118 insertions(+), 113 deletions(-) diff --git a/package-lock.json b/package-lock.json index 452dbfa..83c4eef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6386,7 +6386,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -6801,7 +6802,8 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -6857,6 +6859,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -6900,12 +6903,14 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, diff --git a/src/workspace/js/solutions/task13.js b/src/workspace/js/solutions/task13.js index ae1c149..90ba2bb 100644 --- a/src/workspace/js/solutions/task13.js +++ b/src/workspace/js/solutions/task13.js @@ -1,6 +1,5 @@ -let no = [45,23,767,921] +let no = [45, 23, 767, 921]; -for(i=0;i23) - console.log(no[i]) -} \ No newline at end of file +for (let i = 0; i < no.length; i++) { + if (no[i] > 23) console.log(no[i]); +} diff --git a/src/workspace/js/solutions/task14.js b/src/workspace/js/solutions/task14.js index d42955c..f900ae3 100644 --- a/src/workspace/js/solutions/task14.js +++ b/src/workspace/js/solutions/task14.js @@ -1,20 +1,20 @@ -let a = ['ABC', 'GHI', 'DEF', 'JKL'] -let b = [1,2,3] -a.pop() -console.log(a) -a.push('PQR') -console.log(a) -a.shift() -console.log(a) -a.splice(1,2,"WER","ERT") -console.log(a) -a = a.concat(b) -console.log(a) -a.sort() -console.log(a) -a.reverse() -console.log(a) -let c = b.map((element)=> { - return 2*element -}) -console.log(c) \ No newline at end of file +let a = ['ABC', 'GHI', 'DEF', 'JKL']; +let b = [1, 2, 3]; +a.pop(); +console.log(a); +a.push('PQR'); +console.log(a); +a.shift(); +console.log(a); +a.splice(1, 2, 'WER', 'ERT'); +console.log(a); +a = a.concat(b); +console.log(a); +a.sort(); +console.log(a); +a.reverse(); +console.log(a); +let c = b.map(element => { + return 2 * element; +}); +console.log(c); diff --git a/src/workspace/js/solutions/task15.js b/src/workspace/js/solutions/task15.js index 8de0c56..e6583c4 100644 --- a/src/workspace/js/solutions/task15.js +++ b/src/workspace/js/solutions/task15.js @@ -1,8 +1,8 @@ let person = { - age: 75, - gender: "female" -} + age: 75, + gender: 'female', +}; -let yyyy = 2019-person.age -console.log(yyyy) -console.log(person.gender) \ No newline at end of file +let yyyy = 2019 - person.age; +console.log(yyyy); +console.log(person.gender); diff --git a/src/workspace/js/solutions/task16.js b/src/workspace/js/solutions/task16.js index db53897..1e00db9 100644 --- a/src/workspace/js/solutions/task16.js +++ b/src/workspace/js/solutions/task16.js @@ -1,5 +1,5 @@ -console.log(Math.round(5.57)) -console.log(Math.pow(6,3)) -console.log(Math.sqrt(841)) -console.log(Math.ceil(5.3)) -console.log(Math.floor(5.3)) \ No newline at end of file +console.log(Math.round(5.57)); +console.log(Math.pow(6, 3)); +console.log(Math.sqrt(841)); +console.log(Math.ceil(5.3)); +console.log(Math.floor(5.3)); diff --git a/src/workspace/js/solutions/task17.js b/src/workspace/js/solutions/task17.js index edfd647..285b705 100644 --- a/src/workspace/js/solutions/task17.js +++ b/src/workspace/js/solutions/task17.js @@ -1,23 +1,24 @@ +let day; switch (new Date().getDay()) { - case 0: - day = "Sunday"; - break; - case 1: - day = "Monday"; - break; - case 2: - day = "Tuesday"; - break; - case 3: - day = "Wednesday"; - break; - case 4: - day = "Thursday"; - break; - case 5: - day = "Friday"; - break; - case 6: - day = "Saturday"; - } - console.log(day) \ No newline at end of file + case 0: + day = 'Sunday'; + break; + case 1: + day = 'Monday'; + break; + case 2: + day = 'Tuesday'; + break; + case 3: + day = 'Wednesday'; + break; + case 4: + day = 'Thursday'; + break; + case 5: + day = 'Friday'; + break; + case 6: + day = 'Saturday'; +} +console.log(day); diff --git a/src/workspace/js/solutions/task18.js b/src/workspace/js/solutions/task18.js index 35b8bd3..4b3673c 100644 --- a/src/workspace/js/solutions/task18.js +++ b/src/workspace/js/solutions/task18.js @@ -1,8 +1,8 @@ -let a = true.toString(); +let a = true.toString(); let b = false.toString(); -console.log(typeof a) -console.log(typeof b) -let c = true -let d = false -console.log(typeof c) -console.log(typeof d) \ No newline at end of file +console.log(typeof a); +console.log(typeof b); +let c = true; +let d = false; +console.log(typeof c); +console.log(typeof d); diff --git a/src/workspace/js/solutions/task19.js b/src/workspace/js/solutions/task19.js index e58ddc2..75bd5a3 100644 --- a/src/workspace/js/solutions/task19.js +++ b/src/workspace/js/solutions/task19.js @@ -1,8 +1,8 @@ -let a = 10 -function abc(){ - let a = 4 - console.log(a) +let a = 10; +function abc() { + let a = 4; + console.log(a); } -abc() -console.log(a) \ No newline at end of file +abc(); +console.log(a); diff --git a/src/workspace/js/solutions/task20.js b/src/workspace/js/solutions/task20.js index a210ecc..377d613 100644 --- a/src/workspace/js/solutions/task20.js +++ b/src/workspace/js/solutions/task20.js @@ -1,5 +1,5 @@ const pounds = [11.21, 19.21, 46.21]; -const sum = pounds.reduce((total, amount) => total + amount); +const sum = pounds.reduce((total, amount) => total + amount); -console.log(sum); \ No newline at end of file +console.log(sum); diff --git a/src/workspace/js/solutions/task21.js b/src/workspace/js/solutions/task21.js index fb68b7d..3884f70 100644 --- a/src/workspace/js/solutions/task21.js +++ b/src/workspace/js/solutions/task21.js @@ -2,8 +2,8 @@ const numbers = [1, 3, 4, 6, 8, 9]; const filterValues = () => { return numbers.filter(number => { - return number % 2 == 0; + return number % 2 === 0; }); -} +}; -console.log(filterValues()); \ No newline at end of file +console.log(filterValues()); diff --git a/src/workspace/js/solutions/task22.js b/src/workspace/js/solutions/task22.js index ed48c3b..794e938 100644 --- a/src/workspace/js/solutions/task22.js +++ b/src/workspace/js/solutions/task22.js @@ -1,3 +1,3 @@ -let a = [3,9,12,15,18] -console.log(a.indexOf(15,2)) -console.log(a.indexOf(14,1)) \ No newline at end of file +let a = [3, 9, 12, 15, 18]; +console.log(a.indexOf(15, 2)); +console.log(a.indexOf(14, 1)); diff --git a/src/workspace/js/solutions/task23.js b/src/workspace/js/solutions/task23.js index 8c86e38..caea11f 100644 --- a/src/workspace/js/solutions/task23.js +++ b/src/workspace/js/solutions/task23.js @@ -1,7 +1,7 @@ let obj = { - name: 'ABC', - education: 'CSE' -} -console.log(Object.keys(obj)) -let arr = ['A','B', 'C'] -console.log(Object.keys(arr)) + name: 'ABC', + education: 'CSE', +}; +console.log(Object.keys(obj)); +let arr = ['A', 'B', 'C']; +console.log(Object.keys(arr)); diff --git a/src/workspace/js/solutions/task24.js b/src/workspace/js/solutions/task24.js index 5d4a83b..278cfa6 100644 --- a/src/workspace/js/solutions/task24.js +++ b/src/workspace/js/solutions/task24.js @@ -1,10 +1,10 @@ let text = '{ "name":"John", "age":"39", "city":"New York"}'; -let obj = JSON.parse(text, function (key, value) { - if (key == "city") { +let obj = JSON.parse(text, function(key, value) { + if (key === 'city') { return value.toUpperCase(); } else { return value; } }); -console.log(obj) \ No newline at end of file +console.log(obj); diff --git a/src/workspace/js/solutions/task25.js b/src/workspace/js/solutions/task25.js index 7404e80..18b0b14 100644 --- a/src/workspace/js/solutions/task25.js +++ b/src/workspace/js/solutions/task25.js @@ -1 +1 @@ -console.log(JSON.stringify({x:5, y:6})) \ No newline at end of file +console.log(JSON.stringify({ x: 5, y: 6 })); diff --git a/src/workspace/js/solutions/task26.js b/src/workspace/js/solutions/task26.js index 0dfcd90..fb48f21 100644 --- a/src/workspace/js/solutions/task26.js +++ b/src/workspace/js/solutions/task26.js @@ -1,3 +1,3 @@ -let goals = ['Mission', 'Vision', 'Dedication'] -console.log(goals.includes('Mission')) -console.log(goals.includes('Success')) +let goals = ['Mission', 'Vision', 'Dedication']; +console.log(goals.includes('Mission')); +console.log(goals.includes('Success')); diff --git a/src/workspace/js/solutions/task27.js b/src/workspace/js/solutions/task27.js index c9a6bc8..12911bb 100644 --- a/src/workspace/js/solutions/task27.js +++ b/src/workspace/js/solutions/task27.js @@ -1,9 +1,9 @@ const array1 = ['abc', 'bcd', 'cde']; -array1.forEach(item => console.log(item)) +array1.forEach(item => console.log(item)); for (const element of array1) { console.log(element); } for (const index in array1) { - console.log(index); + console.log(index); } diff --git a/src/workspace/js/solutions/task28.js b/src/workspace/js/solutions/task28.js index 3c1c28f..143ba3b 100644 --- a/src/workspace/js/solutions/task28.js +++ b/src/workspace/js/solutions/task28.js @@ -1,6 +1,6 @@ -let str = 'JS is AWESOME!' -let arr = str.split(" "); -console.log(arr) -let a = ['I', 'love', 'JS!'] -let s = a.join(" ") -console.log(s) \ No newline at end of file +let str = 'JS is AWESOME!'; +let arr = str.split(' '); +console.log(arr); +let a = ['I', 'love', 'JS!']; +let s = a.join(' '); +console.log(s); diff --git a/src/workspace/js/solutions/task29.js b/src/workspace/js/solutions/task29.js index 08b461c..7a25fcf 100644 --- a/src/workspace/js/solutions/task29.js +++ b/src/workspace/js/solutions/task29.js @@ -1,6 +1,6 @@ -let str = 'Hello, I am a novice JS Developer.' -console.log(str.startsWith('Hello')) -console.log(str.endsWith('Develop')) -let str1 = 'I am a Polyglot' -console.log(str1.substr(str1.indexOf('P'), str1.indexOf('t'))) -console.log(str1.substring(str1.indexOf('a'), str1.indexOf('t')+1)) \ No newline at end of file +let str = 'Hello, I am a novice JS Developer.'; +console.log(str.startsWith('Hello')); +console.log(str.endsWith('Develop')); +let str1 = 'I am a Polyglot'; +console.log(str1.substr(str1.indexOf('P'), str1.indexOf('t'))); +console.log(str1.substring(str1.indexOf('a'), str1.indexOf('t') + 1)); diff --git a/src/workspace/js/solutions/task30.js b/src/workspace/js/solutions/task30.js index 2d16a02..26eafd8 100644 --- a/src/workspace/js/solutions/task30.js +++ b/src/workspace/js/solutions/task30.js @@ -1,10 +1,10 @@ let counter = 0; const startCounter = () => { - counter++; - process.stdout.write(`${counter} `); + counter++; + process.stdout.write(`${counter} `); }; const interval = setInterval(startCounter, 1000); -setTimeout(() => clearInterval(interval), 6000); \ No newline at end of file +setTimeout(() => clearInterval(interval), 6000);