From 25d2b71145bd4b6f146ea091cc383a4abd63707d Mon Sep 17 00:00:00 2001 From: swathiu92 Date: Tue, 22 Aug 2017 22:34:12 +0530 Subject: [PATCH 1/2] day 1 assignment --- Day-1/index.html | 77 ++++++++++++++++++++++++++++++++++ Day-1/script.js | 106 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 183 insertions(+) create mode 100644 Day-1/index.html create mode 100644 Day-1/script.js diff --git a/Day-1/index.html b/Day-1/index.html new file mode 100644 index 0000000..b9b8d9c --- /dev/null +++ b/Day-1/index.html @@ -0,0 +1,77 @@ + + + + +My App + + +
+

Factorial

+

Please enter number

+ + +

Output:

+

+
+
+

Sum of Natural Numbers

+

Please click

+ +

Output:

+

+
+
+

Power of 2

+

Please enter number

+ + +

Output:

+

+
+
+

Fizz Buzz

+

Please enter number

+ + +

Output:

+

+
+
+

Array Function

+

Find all pairs in [1, 4, 3, 5, 4, 6, 7, 8, 3] of integers whose sum is equal to 8.

+ +

Output:

+

+
+
+

Array Repeat

+

Print all the numbers that are repeating in [1, 2, 3, 5, 8, 4, 7, 9, 1, 4, 12, 5, 6, 5, 2, 1, 0, 8, 1]

+ +

Output:

+

+
+
+

Object

+

Get amount paid in {"Rick": 85, "Amit": 42, "George": 53, "Tanya": 60, "Linda": 35}

+ +

Output:

+

+
+
+

Palindrome

+

Please enter a string

+ + +

Output:

+

+
+
+

Palindrome in array

+

Please return palidrome in ["Malayalam", "tree", "boat", "civic", "melt", "level"]

+ + +

Output:

+

+
+ + \ No newline at end of file diff --git a/Day-1/script.js b/Day-1/script.js new file mode 100644 index 0000000..8c74192 --- /dev/null +++ b/Day-1/script.js @@ -0,0 +1,106 @@ +var factorial = function(){ + var value = document.getElementById("factorial").value; + var factorial = 1; + for(var idx=1; idx<=value; idx++) { + factorial = factorial * idx; + } + document.getElementById("getfactorial").innerHTML = factorial; +}; +var natural = function(){ + var natural = 0; + for(var idx=1; idx<=500; idx++) { + natural = natural + idx; + } + document.getElementById("natural").innerHTML = natural; +}; +var naturalMultiples = function(){ + var naturalMultiple = 0; + for(var idx=1; idx<1000; idx++) { + if(idx % 3 === 0 || idx % 5 === 0) { + naturalMultiple = naturalMultiple + idx; + } + } + document.getElementById("naturalMultiple").innerHTML = naturalMultiple; +}; +var powerCheck = function(){ + var value = document.getElementById("power").value; + var power; + for(var idx=1; idx<=value; idx++) { + if(Math.pow(2, idx) <= value) { + power = idx; + } else { + break; + } + } + document.getElementById("getpower").innerHTML = power; +}; +var multiplesCheck = function(){ + var value = document.getElementById("multiples").value; + var multiples = []; + for(var idx=1; idx<=value; idx++) { + if(idx % 3 === 0){ + multiples.push("Fizz"); + } else if (idx % 5 === 0) { + multiples.push("Buzz"); + } else { + multiples.push(idx); + } + } + document.getElementById("getmultiple").innerHTML = multiples.join(" , "); +}; +var arrayFunc = function(){ + var array = [1, 4, 3, 5, 4, 6, 7, 8, 3]; + var sum = 8; + var finalArray = []; + for(var i = 0; i<= array.length; i++) { + for(var idx = i+1; idx <= array.length; idx++) { + if(array[i] + array[idx] === sum) { + finalArray.push(array[i] + " , " + array[idx]); + } + } + } + document.getElementById("finalArray").innerHTML = finalArray.join("\r\n"); +}; +var arrayRepeat = function(){ + var array = [1, 2, 3, 5, 8, 4, 7, 9, 1, 4, 12, 5, 6, 5, 2, 1, 0, 8, 1, 12, 9]; + var finalArray = []; + for(var i = 0; i<= array.length; i++) { + for(var idx = i+1; idx <= array.length; idx++) { + if(array[i] === array[idx] && finalArray.indexOf(array[i]) < 0) { + finalArray.push(array[i]); + } + } + } + document.getElementById("finalArrayRepeat").innerHTML = finalArray.join(" , "); +}; +var amountPaid = function(){ + var amount = {"Rick": 85, "Amit": 42, "George": 53, "Tanya": 60, "Linda": 35}; + var amountPaid = 0; + for(var idx in amount) { + amountPaid = amountPaid + amount[idx]; + } + document.getElementById("amount").innerHTML = amountPaid; +}; +var palindromeCheck = function(palindromeValue){ + var value = (palindromeValue)?palindromeValue:document.getElementById("palindrome").value; + var palindrome = value.split(""); + if(value === palindrome.reverse().join("")) { + (!palindromeValue)?document.getElementById("getpalindrome").innerHTML = "It is a palindrome":""; + return true; + } else { + (!palindromeValue)?document.getElementById("getpalindrome").innerHTML = "It is not a palindrome":""; + return false; + } + +}; +var palindromeArray = function(){ + var finalArray = []; + var array = ["Malayalam", "tree", "boat", "civic", "melt", "level"]; + for(var idx=0; idx< array.length; idx++) { + var a = array[idx].toLowerCase(); + if(palindromeCheck(a)) { + finalArray.push(array[idx]); + } + } + document.getElementById("getpalindromeArray").innerHTML = finalArray.join(" , "); +}; \ No newline at end of file From c947679e146b73f510d6a6f9880f6ddd48ddfb24 Mon Sep 17 00:00:00 2001 From: swathiu92 Date: Tue, 22 Aug 2017 22:44:08 +0530 Subject: [PATCH 2/2] day 1 assignment --- Day-1/index.html | 140 ++++++++++++++++----------------- Day-1/script.js | 198 ++++++++++++++++++++++++----------------------- 2 files changed, 172 insertions(+), 166 deletions(-) diff --git a/Day-1/index.html b/Day-1/index.html index b9b8d9c..2a499d8 100644 --- a/Day-1/index.html +++ b/Day-1/index.html @@ -1,77 +1,77 @@ - -My App + + My App -
-

Factorial

-

Please enter number

- - -

Output:

-

-
-
-

Sum of Natural Numbers

-

Please click

- -

Output:

-

-
-
-

Power of 2

-

Please enter number

- - -

Output:

-

-
-
-

Fizz Buzz

-

Please enter number

- - -

Output:

-

-
-
-

Array Function

-

Find all pairs in [1, 4, 3, 5, 4, 6, 7, 8, 3] of integers whose sum is equal to 8.

- -

Output:

-

-
-
-

Array Repeat

-

Print all the numbers that are repeating in [1, 2, 3, 5, 8, 4, 7, 9, 1, 4, 12, 5, 6, 5, 2, 1, 0, 8, 1]

- -

Output:

-

-
-
-

Object

-

Get amount paid in {"Rick": 85, "Amit": 42, "George": 53, "Tanya": 60, "Linda": 35}

- -

Output:

-

-
-
-

Palindrome

-

Please enter a string

- - -

Output:

-

-
-
-

Palindrome in array

-

Please return palidrome in ["Malayalam", "tree", "boat", "civic", "melt", "level"]

- - -

Output:

-

-
+
+

Factorial

+

Please enter number

+ + +

Output:

+

+
+
+

Sum of Natural Numbers

+

Please click

+ +

Output:

+

+
+
+

Power of 2

+

Please enter number

+ + +

Output:

+

+
+
+

Fizz Buzz

+

Please enter number

+ + +

Output:

+

+
+
+

Array Function

+

Find all pairs in [1, 4, 3, 5, 4, 6, 7, 8, 3] of integers whose sum is equal to 8.

+ +

Output:

+

+
+
+

Array Repeat

+

Print all the numbers that are repeating in [1, 2, 3, 5, 8, 4, 7, 9, 1, 4, 12, 5, 6, 5, 2, 1, 0, 8, 1]

+ +

Output:

+

+
+
+

Object

+

Get amount paid in {"Rick": 85, "Amit": 42, "George": 53, "Tanya": 60, "Linda": 35}

+ +

Output:

+

+
+
+

Palindrome

+

Please enter a string

+ + +

Output:

+

+
+
+

Palindrome in array

+

Please return palidrome in ["Malayalam", "tree", "boat", "civic", "melt", "level"]

+ + +

Output:

+

+
\ No newline at end of file diff --git a/Day-1/script.js b/Day-1/script.js index 8c74192..d1fc828 100644 --- a/Day-1/script.js +++ b/Day-1/script.js @@ -1,106 +1,112 @@ -var factorial = function(){ - var value = document.getElementById("factorial").value; - var factorial = 1; - for(var idx=1; idx<=value; idx++) { - factorial = factorial * idx; - } - document.getElementById("getfactorial").innerHTML = factorial; +var factorial = function() { + var value = document.getElementById("factorial").value; + var factorial = 1; + for (var idx = 1; idx <= value; idx++) { + factorial = factorial * idx; + } + document.getElementById("getfactorial").innerHTML = factorial; }; -var natural = function(){ - var natural = 0; - for(var idx=1; idx<=500; idx++) { - natural = natural + idx; - } - document.getElementById("natural").innerHTML = natural; +var natural = function() { + var natural = 0; + for (var idx = 1; idx <= 500; idx++) { + natural = natural + idx; + } + document.getElementById("natural").innerHTML = natural; }; -var naturalMultiples = function(){ - var naturalMultiple = 0; - for(var idx=1; idx<1000; idx++) { - if(idx % 3 === 0 || idx % 5 === 0) { - naturalMultiple = naturalMultiple + idx; - } - } - document.getElementById("naturalMultiple").innerHTML = naturalMultiple; +var naturalMultiples = function() { + var naturalMultiple = 0; + for (var idx = 1; idx < 1000; idx++) { + if (idx % 3 === 0 || idx % 5 === 0) { + naturalMultiple = naturalMultiple + idx; + } + } + document.getElementById("naturalMultiple").innerHTML = naturalMultiple; }; -var powerCheck = function(){ - var value = document.getElementById("power").value; - var power; - for(var idx=1; idx<=value; idx++) { - if(Math.pow(2, idx) <= value) { - power = idx; - } else { - break; - } - } - document.getElementById("getpower").innerHTML = power; +var powerCheck = function() { + var value = document.getElementById("power").value; + var power; + for (var idx = 1; idx <= value; idx++) { + if (Math.pow(2, idx) <= value) { + power = idx; + } else { + break; + } + } + document.getElementById("getpower").innerHTML = power; }; -var multiplesCheck = function(){ - var value = document.getElementById("multiples").value; - var multiples = []; - for(var idx=1; idx<=value; idx++) { - if(idx % 3 === 0){ - multiples.push("Fizz"); - } else if (idx % 5 === 0) { - multiples.push("Buzz"); - } else { - multiples.push(idx); - } - } - document.getElementById("getmultiple").innerHTML = multiples.join(" , "); +var multiplesCheck = function() { + var value = document.getElementById("multiples").value; + var multiples = []; + for (var idx = 1; idx <= value; idx++) { + if (idx % 3 === 0) { + multiples.push("Fizz"); + } else if (idx % 5 === 0) { + multiples.push("Buzz"); + } else { + multiples.push(idx); + } + } + document.getElementById("getmultiple").innerHTML = multiples.join(" , "); }; -var arrayFunc = function(){ - var array = [1, 4, 3, 5, 4, 6, 7, 8, 3]; - var sum = 8; - var finalArray = []; - for(var i = 0; i<= array.length; i++) { - for(var idx = i+1; idx <= array.length; idx++) { - if(array[i] + array[idx] === sum) { - finalArray.push(array[i] + " , " + array[idx]); - } - } - } - document.getElementById("finalArray").innerHTML = finalArray.join("\r\n"); +var arrayFunc = function() { + var array = [1, 4, 3, 5, 4, 6, 7, 8, 3]; + var sum = 8; + var finalArray = []; + for (var i = 0; i <= array.length; i++) { + for (var idx = i + 1; idx <= array.length; idx++) { + if (array[i] + array[idx] === sum) { + finalArray.push(array[i] + " , " + array[idx]); + } + } + } + document.getElementById("finalArray").innerHTML = finalArray.join("\r\n"); }; -var arrayRepeat = function(){ - var array = [1, 2, 3, 5, 8, 4, 7, 9, 1, 4, 12, 5, 6, 5, 2, 1, 0, 8, 1, 12, 9]; - var finalArray = []; - for(var i = 0; i<= array.length; i++) { - for(var idx = i+1; idx <= array.length; idx++) { - if(array[i] === array[idx] && finalArray.indexOf(array[i]) < 0) { - finalArray.push(array[i]); - } - } - } - document.getElementById("finalArrayRepeat").innerHTML = finalArray.join(" , "); +var arrayRepeat = function() { + var array = [1, 2, 3, 5, 8, 4, 7, 9, 1, 4, 12, 5, 6, 5, 2, 1, 0, 8, 1, 12, 9]; + var finalArray = []; + for (var i = 0; i <= array.length; i++) { + for (var idx = i + 1; idx <= array.length; idx++) { + if (array[i] === array[idx] && finalArray.indexOf(array[i]) < 0) { + finalArray.push(array[i]); + } + } + } + document.getElementById("finalArrayRepeat").innerHTML = finalArray.join(" , "); }; -var amountPaid = function(){ - var amount = {"Rick": 85, "Amit": 42, "George": 53, "Tanya": 60, "Linda": 35}; - var amountPaid = 0; - for(var idx in amount) { - amountPaid = amountPaid + amount[idx]; - } - document.getElementById("amount").innerHTML = amountPaid; +var amountPaid = function() { + var amount = { + "Rick": 85, + "Amit": 42, + "George": 53, + "Tanya": 60, + "Linda": 35 + }; + var amountPaid = 0; + for (var idx in amount) { + amountPaid = amountPaid + amount[idx]; + } + document.getElementById("amount").innerHTML = amountPaid; }; -var palindromeCheck = function(palindromeValue){ - var value = (palindromeValue)?palindromeValue:document.getElementById("palindrome").value; - var palindrome = value.split(""); - if(value === palindrome.reverse().join("")) { - (!palindromeValue)?document.getElementById("getpalindrome").innerHTML = "It is a palindrome":""; - return true; - } else { - (!palindromeValue)?document.getElementById("getpalindrome").innerHTML = "It is not a palindrome":""; - return false; - } - +var palindromeCheck = function(palindromeValue) { + var value = (palindromeValue) ? palindromeValue : document.getElementById("palindrome").value; + var palindrome = value.split(""); + if (value === palindrome.reverse().join("")) { + (!palindromeValue) ? document.getElementById("getpalindrome").innerHTML = "It is a palindrome": ""; + return true; + } else { + (!palindromeValue) ? document.getElementById("getpalindrome").innerHTML = "It is not a palindrome": ""; + return false; + } + }; -var palindromeArray = function(){ - var finalArray = []; - var array = ["Malayalam", "tree", "boat", "civic", "melt", "level"]; - for(var idx=0; idx< array.length; idx++) { - var a = array[idx].toLowerCase(); - if(palindromeCheck(a)) { - finalArray.push(array[idx]); - } - } - document.getElementById("getpalindromeArray").innerHTML = finalArray.join(" , "); +var palindromeArray = function() { + var finalArray = []; + var array = ["Malayalam", "tree", "boat", "civic", "melt", "level"]; + for (var idx = 0; idx < array.length; idx++) { + var a = array[idx].toLowerCase(); + if (palindromeCheck(a)) { + finalArray.push(array[idx]); + } + } + document.getElementById("getpalindromeArray").innerHTML = finalArray.join(" , "); }; \ No newline at end of file