From ac29a51c7e50a6765ffed2dcf13ab8523f13c3fd Mon Sep 17 00:00:00 2001 From: Swaroopaamruthwar Date: Mon, 17 Jan 2022 12:02:00 -0800 Subject: [PATCH 1/8] BMI-Calculator-Assignment --- assignments/bmi_calculator/bmi_calculator.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/assignments/bmi_calculator/bmi_calculator.js b/assignments/bmi_calculator/bmi_calculator.js index 0cdd351..ffeaa49 100644 --- a/assignments/bmi_calculator/bmi_calculator.js +++ b/assignments/bmi_calculator/bmi_calculator.js @@ -1,6 +1,13 @@ // This function should return the BMI for a person function BMICalculator(mass, height) { // Write your code here + if(mass>0 && height>0){ + BMI = mass / (height * height) + return BMI + } + else{ + return "INVALID INPUT"; + } } module.exports = BMICalculator; From 8d1b6ba94cd744bfd6fe29b705db96b82fcb0f44 Mon Sep 17 00:00:00 2001 From: Swaroopaamruthwar Date: Tue, 18 Jan 2022 13:01:13 -0800 Subject: [PATCH 2/8] CanDrive-Assignment --- assignments/can_drive/can_drive.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/assignments/can_drive/can_drive.js b/assignments/can_drive/can_drive.js index f2f1251..9d56844 100644 --- a/assignments/can_drive/can_drive.js +++ b/assignments/can_drive/can_drive.js @@ -1,5 +1,16 @@ function CanDrive(hasDrivingLiscence, isTired, isSober) { // Write you code here + if(hasDrivingLiscence===false){ + return "You cannot drive"; + } + else if(hasDrivingLiscence===true && (isTired===true || isSober===false)){ + return "You shouldn't drive"; + } + else if(hasDrivingLiscence===true && (isTired===false || isSober===true)){ + return "You can drive"; + } } module.exports = CanDrive; + + From a5e3ecceb01cdab88f2d17332f16d7137ca15462 Mon Sep 17 00:00:00 2001 From: Swaroopaamruthwar Date: Wed, 19 Jan 2022 13:13:47 -0800 Subject: [PATCH 3/8] favourite_movie AssignmentSubmission --- assignments/favourite_movie/favourite_movie.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/assignments/favourite_movie/favourite_movie.js b/assignments/favourite_movie/favourite_movie.js index a8148eb..cbc089f 100644 --- a/assignments/favourite_movie/favourite_movie.js +++ b/assignments/favourite_movie/favourite_movie.js @@ -2,6 +2,12 @@ const movies = []; function favouriteMovie(operation, movie) { // Write your code here + if(operation==="add"){ + movies.push(movie); + } + else if(operation==="remove"){ + movies.pop(); + } + return movies; } - module.exports = favouriteMovie; From 77148266a15534740e4875f4a5ae553c7cd49895 Mon Sep 17 00:00:00 2001 From: Swaroopaamruthwar Date: Thu, 20 Jan 2022 12:27:31 -0800 Subject: [PATCH 4/8] run_callback Assignment --- assignments/run_callback/run_callback.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/assignments/run_callback/run_callback.js b/assignments/run_callback/run_callback.js index 04bf43e..6f866b4 100644 --- a/assignments/run_callback/run_callback.js +++ b/assignments/run_callback/run_callback.js @@ -1,5 +1,7 @@ function RunCallback(a, b, cb) { // Write you code here, you need to add a and b, pass the result into callback function cb as argument return the result + var sum=a+b; + return cb(sum); } module.exports = RunCallback; From e0729f27abc01607a53273ea7f9dfc0806ab3c16 Mon Sep 17 00:00:00 2001 From: Swaroopaamruthwar Date: Sat, 22 Jan 2022 12:18:29 -0800 Subject: [PATCH 5/8] play_with_array Assignment --- assignments/play_with_array/play_with_array.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/assignments/play_with_array/play_with_array.js b/assignments/play_with_array/play_with_array.js index 0601c6f..e30cbc2 100644 --- a/assignments/play_with_array/play_with_array.js +++ b/assignments/play_with_array/play_with_array.js @@ -7,7 +7,8 @@ function getEven(arr) { Write you code below */ - + var res=arr.filter(number=>number%2===0); + return res } function multiplyByN(arr, n) { @@ -18,6 +19,8 @@ function multiplyByN(arr, n) { Output: [3,9,13,165] Write you code below */ + var mul=arr.map(number=>number*n) + return mul } function removeNthElement(arr, n) { @@ -28,6 +31,8 @@ function removeNthElement(arr, n) { Output: [1,3,4,7] Write you code below */ + arr.splice(n,1); + return arr } module.exports = { From 34b2d2bb13dfde165a7d25ef0b0cfbd97e8b257a Mon Sep 17 00:00:00 2001 From: Swaroopaamruthwar Date: Sun, 23 Jan 2022 10:00:06 -0800 Subject: [PATCH 6/8] create_object Assignment --- assignments/create_object/create_object.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/assignments/create_object/create_object.js b/assignments/create_object/create_object.js index 775bc8c..09e0a33 100644 --- a/assignments/create_object/create_object.js +++ b/assignments/create_object/create_object.js @@ -1,5 +1,12 @@ function CreateObject(arr) { // Write your code here + obj={}; + arr.forEach((element,index,arr)=>{ + if(index%2===0){ + obj[element]=arr[index+1]; + } + }); + return obj; } module.exports = CreateObject; From 1d6dda13f78e2ae844566323969dd51333cd5c5c Mon Sep 17 00:00:00 2001 From: Swaroopaamruthwar Date: Thu, 27 Jan 2022 17:39:12 -0800 Subject: [PATCH 7/8] todo_list Assignment --- assignments/todo_list/script.js | 17 +++++++++++++++++ assignments/todo_list/todo.html | 14 +++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/assignments/todo_list/script.js b/assignments/todo_list/script.js index e69de29..a253b43 100644 --- a/assignments/todo_list/script.js +++ b/assignments/todo_list/script.js @@ -0,0 +1,17 @@ +var todoButton = document.querySelector('button'); +var userInput= document.querySelector('input'); +var todoList = document.querySelector('.todos') +var count = 0; +todoButton.addEventListener("click", AddTodo) +function AddTodo(){ + var todo=document.createElement('p'); + todo.setAttribute('key',count); + count=count+1; + todo.innerHTML=userInput.value; + todoList.appendChild(todo); + userInput.value=''; + todo.addEventListener('click',function(e){ + todoList.removeChild(todo); + }) +} + diff --git a/assignments/todo_list/todo.html b/assignments/todo_list/todo.html index 8f6fac5..595b5c3 100644 --- a/assignments/todo_list/todo.html +++ b/assignments/todo_list/todo.html @@ -1,12 +1,24 @@ Todo List +
-
+
+
From ab94cc711ce01a7add57a4aed67b8274b7522f55 Mon Sep 17 00:00:00 2001 From: Swaroopaamruthwar Date: Sun, 30 Jan 2022 22:05:02 -0800 Subject: [PATCH 8/8] Todo_list with actual api Assignment --- assignments/todo_list/script1.js | 37 ++++++++++++++++++++++++++++++++ assignments/todo_list/todo.html | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 assignments/todo_list/script1.js diff --git a/assignments/todo_list/script1.js b/assignments/todo_list/script1.js new file mode 100644 index 0000000..31b6dfd --- /dev/null +++ b/assignments/todo_list/script1.js @@ -0,0 +1,37 @@ +var todoButton = document.querySelector('button'); +var inputfield = document.querySelector('input'); +var todoList= document.querySelector('div.todos') +var todos=[] + +async function callAPI(){ + try{ + const response=await fetch('https://jsonplaceholder.typicode.com/todos') + .then(response=>response.json()) + .then(json=>{ + // const json=response.json() + todos=json.slice(0,10) + console.log(todos) + todos.forEach((todo,index)=>{ + const newTodo =document.createElement('p') + newTodo.setAttribute('key',index) + newTodo.innerHTML=todo.title + todoList.appendChild(newTodo) + }) + }) + .catch((e)=>console.log(e)) + } + catch(e){ + console.log(e); + } +} +callAPI() + +todoButton.addEventListener('click',function(){ + todoList.innerHTML='' + todos.filter(todo => todo.completed).forEach((todo,index)=>{ + const newTodo=document.createElement('p') + newTodo.setAttribute('key',index) + newTodo.innerHTML=todo.title + todoList.appendChild(newTodo) ; + }) +}) \ No newline at end of file diff --git a/assignments/todo_list/todo.html b/assignments/todo_list/todo.html index 595b5c3..12fcf38 100644 --- a/assignments/todo_list/todo.html +++ b/assignments/todo_list/todo.html @@ -21,5 +21,5 @@ - + \ No newline at end of file