Skip to content
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
7 changes: 7 additions & 0 deletions assignments/bmi_calculator/bmi_calculator.js
Original file line number Diff line number Diff line change
@@ -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;
11 changes: 11 additions & 0 deletions assignments/can_drive/can_drive.js
Original file line number Diff line number Diff line change
@@ -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;


7 changes: 7 additions & 0 deletions assignments/create_object/create_object.js
Original file line number Diff line number Diff line change
@@ -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;
8 changes: 7 additions & 1 deletion assignments/favourite_movie/favourite_movie.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
7 changes: 6 additions & 1 deletion assignments/play_with_array/play_with_array.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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 = {
Expand Down
2 changes: 2 additions & 0 deletions assignments/run_callback/run_callback.js
Original file line number Diff line number Diff line change
@@ -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;
17 changes: 17 additions & 0 deletions assignments/todo_list/script.js
Original file line number Diff line number Diff line change
@@ -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);
})
}

37 changes: 37 additions & 0 deletions assignments/todo_list/script1.js
Original file line number Diff line number Diff line change
@@ -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) ;
})
})
16 changes: 14 additions & 2 deletions assignments/todo_list/todo.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
<html>
<head>
<title>Todo List</title>
<style>
*{
margin:0;
padding:0;
}
body{
display:flex;
justify-content:center;
margin:200px auto;
}
</style>
</head>
<body>
<div>
<input type='text' name='todo_input'>
<button type='submit'>Add Todo</button>
<div class='todos'></div>
<div class='todos'>
</div>
</div>
</body>
<script src='./script.js'></script>
<script src='./script1.js'></script>
</html>