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; 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; + + 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; 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; 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 = { 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;