From 44bfc83110f3393c0fd1b7c9b1500b4c51bbe1be Mon Sep 17 00:00:00 2001 From: K C Gaurab Date: Mon, 8 Apr 2019 20:08:15 +0300 Subject: [PATCH 1/4] Array exercises --- Lect4ArraEx/ex4.js | 13 +++++++++++++ Lect4ArraEx/ex5.js | 11 +++++++++++ Lect4ArraEx/ex6.js | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 Lect4ArraEx/ex4.js create mode 100644 Lect4ArraEx/ex5.js create mode 100644 Lect4ArraEx/ex6.js diff --git a/Lect4ArraEx/ex4.js b/Lect4ArraEx/ex4.js new file mode 100644 index 0000000..91a04a0 --- /dev/null +++ b/Lect4ArraEx/ex4.js @@ -0,0 +1,13 @@ +function largestOfFive(arr){ + var greatestNumber=arr[0]; + + for(i=1;i arr[0]){ + greatestNumber= arr[i] + + } + + } +return greatestNumber; +} +console.log(largestOfFive([15,24,-7,9])) \ No newline at end of file diff --git a/Lect4ArraEx/ex5.js b/Lect4ArraEx/ex5.js new file mode 100644 index 0000000..e41f357 --- /dev/null +++ b/Lect4ArraEx/ex5.js @@ -0,0 +1,11 @@ +function isOdd(numbers){ + for(i=0; i< numbers.length;i++){ + if(numbers[i]%2 === 0){ + console.log(numbers[i]+ " is even"); ; + } + else{ + console.log(numbers[i]+ " is odd"); + } + } +} +console.log(isOdd([20,56,7,8,9])); \ No newline at end of file diff --git a/Lect4ArraEx/ex6.js b/Lect4ArraEx/ex6.js new file mode 100644 index 0000000..17e18b6 --- /dev/null +++ b/Lect4ArraEx/ex6.js @@ -0,0 +1,35 @@ +/*Write a JavaScript program which compute, the average marks of the following students Then, this average is used to determine the corresponding grade. +Student Name Marks +David 80 +Vinoth 77 +Divya 88 +Ishitha 95 +Thomas 68 +The grades are computed as follows: +Range Grade + <60 F + <70 D + <80 C + <90 B + <100 A*/ + + function getGrade(name, points) { + var total = 0; + for (i = 0; i < points.length; i++) { + total += points[i]; + var average = total / points.length; + } + if (average < 60) { + return name + " has failed"; + } else if (average < 70) { + return name + " has scored D"; + } else if (average >= 70 && average < 80) { + return name + " has scored C"; + } else if (average >= 80 && average < 90) { + return name + " has scored B" + } else if (average >= 90) { + return name + " has scored A" + } + + } + console.log(getGrade('Stanley', [67, 76, 67, 79])); \ No newline at end of file From 6b78ce58a2c2ccfc32df6dfdad07c1f5f7c1e1c7 Mon Sep 17 00:00:00 2001 From: K C Gaurab Date: Mon, 8 Apr 2019 21:12:28 +0300 Subject: [PATCH 2/4] exercise 7 --- Lect4ArraEx.1/ex7.js | 12 ++++++++++++ Lect4ArraEx.1/ex8.js | 6 ++++++ 2 files changed, 18 insertions(+) create mode 100644 Lect4ArraEx.1/ex7.js create mode 100644 Lect4ArraEx.1/ex8.js diff --git a/Lect4ArraEx.1/ex7.js b/Lect4ArraEx.1/ex7.js new file mode 100644 index 0000000..a673c22 --- /dev/null +++ b/Lect4ArraEx.1/ex7.js @@ -0,0 +1,12 @@ +/*Write a JavaScript program which iterates the integers from 1 to 100. +But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". +For numbers which are multiples of both three and five print "FizzBuzz*/ + +function fizzyBuzzy(){ + for(i=0;i<101;i++){ + if(i%15 === 0)console.log("fizzbuzz"); + else if(i%3 === 0)console.log("fizz"); + else if(i%5 === 0)console.log("buzz"); + else console.log(i); + }} + console.log(fizzyBuzzy()); \ No newline at end of file diff --git a/Lect4ArraEx.1/ex8.js b/Lect4ArraEx.1/ex8.js new file mode 100644 index 0000000..b2f6133 --- /dev/null +++ b/Lect4ArraEx.1/ex8.js @@ -0,0 +1,6 @@ +/*8. According to Wikipedia a happy number is defined by the following process: +"Starting with any positive integer, replace the number by the sum of the squares of its digits, + and repeat the process until the number equals 1 (where it will stay), + or it loops endlessly in a cycle which does not include 1. Those +numbers for which this process ends in 1 are happy numbers, +while those that do not end in 1 are unhappy numbers (or sad numbers)".*/ \ No newline at end of file From f9ac945fe4d5d3eb690b097d2d3bf9b1c3bfa463 Mon Sep 17 00:00:00 2001 From: K C Gaurab Date: Mon, 8 Apr 2019 23:57:09 +0300 Subject: [PATCH 3/4] added option that deosn't take empty input --- Lect4ArraEx/toDolist/styling.css | 0 Lect4ArraEx/toDolist/todolist.html | 51 ++++++++++++++++++++++++++++++ Lect4ArraEx/toDolist/todolist.js | 51 ++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 Lect4ArraEx/toDolist/styling.css create mode 100644 Lect4ArraEx/toDolist/todolist.html create mode 100644 Lect4ArraEx/toDolist/todolist.js diff --git a/Lect4ArraEx/toDolist/styling.css b/Lect4ArraEx/toDolist/styling.css new file mode 100644 index 0000000..e69de29 diff --git a/Lect4ArraEx/toDolist/todolist.html b/Lect4ArraEx/toDolist/todolist.html new file mode 100644 index 0000000..055fb61 --- /dev/null +++ b/Lect4ArraEx/toDolist/todolist.html @@ -0,0 +1,51 @@ + + + + + + + + + To do list application + + + + + + + + + +

THE TODO LIST

+
+ +
+ + + +

Tasks to do

+
+
    + +
+
+ +
Completed tasks
+
+
    + +
+
+ + + + \ No newline at end of file diff --git a/Lect4ArraEx/toDolist/todolist.js b/Lect4ArraEx/toDolist/todolist.js new file mode 100644 index 0000000..055fb61 --- /dev/null +++ b/Lect4ArraEx/toDolist/todolist.js @@ -0,0 +1,51 @@ + + + + + + + + + To do list application + + + + + + + + + +

THE TODO LIST

+
+ +
+ + + +

Tasks to do

+
+
    + +
+
+ +
Completed tasks
+
+
    + +
+
+ + + + \ No newline at end of file From 7720ffd02dd8f6d84919106127286470e5cfe8ee Mon Sep 17 00:00:00 2001 From: K C Gaurab Date: Mon, 8 Apr 2019 23:59:38 +0300 Subject: [PATCH 4/4] Update todolist.js --- Lect4ArraEx/toDolist/todolist.js | 75 ++++++++++---------------------- 1 file changed, 24 insertions(+), 51 deletions(-) diff --git a/Lect4ArraEx/toDolist/todolist.js b/Lect4ArraEx/toDolist/todolist.js index 055fb61..fb9c5fb 100644 --- a/Lect4ArraEx/toDolist/todolist.js +++ b/Lect4ArraEx/toDolist/todolist.js @@ -1,51 +1,24 @@ - - - - - - - - - To do list application - - - - - - - - - -

THE TODO LIST

-
- -
- - - -

Tasks to do

-
-
    - -
-
- -
Completed tasks
-
-
    - -
-
- - - - \ No newline at end of file +$(document).ready(function () { + + + $('.addTask').click(function () { + if ($.trim($('#inputField').val()) == '') { + alert('Please enter a task'); + } else { + var inputText = $('#inputField').val(); + $('.addedTasks .taskList').append('
  • ' + inputText + '
  • '); + $('#inputField').val(''); + } + }); + + +}); +$(document).on('click', '.markAsDone', function () { + var inputText = this.parentNode.firstChild.nodeValue; + $('.doneTasks .taskList').append('
  • ' + inputText + '
  • '); + this.parentNode.remove(); +}); + +$(document).on('click', '.removeTask', function () { +this.parentNode.remove(); +});