From df48cdf419746f1259312025be036941ab8647f4 Mon Sep 17 00:00:00 2001 From: Justice Lee Date: Tue, 5 Nov 2019 13:25:40 -0500 Subject: [PATCH 1/6] finished add and subtract exercise --- my-script.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/my-script.js b/my-script.js index 5ac970c..89ee8ab 100644 --- a/my-script.js +++ b/my-script.js @@ -22,11 +22,25 @@ const greeting = (name) => { * Write a function called `add` that returns the sum of two numbers */ + function add(a,b){ + add = a+b; + return add; +} + +console.log(add(10,15)); + /** * Write a function called `subtract` that returns the difference between two numbers */ + function subtract(a,b){ + subtract = a-b; + return subtract; + } + + console.log(subtract(10,5)); + /** * Write a function called `min` that returns the smaller of two numbers @@ -85,4 +99,3 @@ module.exports = { oddFactorial: typeof oddFactorial === 'function' ? oddFactorial : null, chessboard: typeof chessboard === 'function' ? chessboard : null, }; - From a6f3ab3771424a3d32ec38bfa3b861b343093faf Mon Sep 17 00:00:00 2001 From: Justice Lee Date: Tue, 5 Nov 2019 15:39:39 -0500 Subject: [PATCH 2/6] finished factorial exercise and working on isEven and isOdd --- my-script.js | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/my-script.js b/my-script.js index 89ee8ab..ea4877a 100644 --- a/my-script.js +++ b/my-script.js @@ -27,9 +27,6 @@ const greeting = (name) => { return add; } -console.log(add(10,15)); - - /** * Write a function called `subtract` that returns the difference between two numbers */ @@ -39,35 +36,66 @@ console.log(add(10,15)); return subtract; } - console.log(subtract(10,5)); - - /** * Write a function called `min` that returns the smaller of two numbers */ + function min(a, b){ + min=Math.min(a, b); + return min; +}; /** * Write a function called `max` that returns the larger of two numbers */ + function max(a, b){ + max=Math.max(a, b); + return max; +}; + /** * Write a function called `isEven` that takes a single value and * returns `true` if it is even and `false` if it is odd */ + function isEven(a){ + if(a % 2 == 0){ + console.log("True"); + } + else{ + console.log("False"); + } + } + /** * Write a function called `isOdd` that takes a single value and * returns `false` if it is even and `true` if it is odd */ + function isOdd(a){ + if(isOdd % 2 != 0){ + console.log("True"); + } + else{ + console.log("False"); + } + } /** * Write a function called `factorial` that takes a single integer and * returns the product of the integer and all the integers below it */ + function factorial(a){ + if (a == 0){ + return 1; + } + else { + return factorial(a-1)*a; + } + } /** * Write a function called `oddFactorial` that takes a single integer and From a33f4587a7592ddb0e4e9e2cdcf54d4cf2207b54 Mon Sep 17 00:00:00 2001 From: Justice Lee Date: Wed, 6 Nov 2019 15:03:09 -0500 Subject: [PATCH 3/6] did oddFactorial --- my-script.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/my-script.js b/my-script.js index ea4877a..971f094 100644 --- a/my-script.js +++ b/my-script.js @@ -103,6 +103,14 @@ const greeting = (name) => { * only if they are odd. If the starting number is even, don't include it. */ + function oddFactorial(a){ + if (a == 0 && a % 2 == 0){ + return 1; + } + else { + return oddFactorial(a-1)*a; + } + } /** * Write a function that solves the Chessboard exercise from chapter two, From 11a19c4db46332c6f76cb15d1d47e52e50c0c15d Mon Sep 17 00:00:00 2001 From: Justice Lee Date: Thu, 7 Nov 2019 20:59:46 -0500 Subject: [PATCH 4/6] worked more on the practices --- my-script.js | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/my-script.js b/my-script.js index 971f094..2e8cc81 100644 --- a/my-script.js +++ b/my-script.js @@ -61,11 +61,12 @@ const greeting = (name) => { function isEven(a){ if(a % 2 == 0){ - console.log("True"); + return true; } else{ - console.log("False"); + return false; } + } @@ -75,11 +76,11 @@ const greeting = (name) => { */ function isOdd(a){ - if(isOdd % 2 != 0){ - console.log("True"); + if(a % 2 != 0){ + return true; } else{ - console.log("False"); + return false; } } @@ -104,13 +105,17 @@ const greeting = (name) => { */ function oddFactorial(a){ - if (a == 0 && a % 2 == 0){ - return 1; - } - else { - return oddFactorial(a-1)*a; - } + for(i=1, answer=1; i<= a; i++){ + if(a % 2 == 0){ + + } + + else{ + answer*= i; + } + return a; } +} /** * Write a function that solves the Chessboard exercise from chapter two, From 0b0f464c58ea1060ab458acbc7bb478decda76b8 Mon Sep 17 00:00:00 2001 From: Justice Lee Date: Mon, 11 Nov 2019 13:00:51 -0500 Subject: [PATCH 5/6] finished oddFactorial --- my-script.js | 51 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/my-script.js b/my-script.js index 2e8cc81..0d19953 100644 --- a/my-script.js +++ b/my-script.js @@ -103,18 +103,30 @@ const greeting = (name) => { * returns the product of the integer and all the integers below it, but * only if they are odd. If the starting number is even, don't include it. */ - +/* function oddFactorial(a){ - for(i=1, answer=1; i<= a; i++){ - if(a % 2 == 0){ - - } + if (a % 2==0){ + a-1; + return a; + } + if(a<=1){ + return 1; + } + else{ + (a-2)*a; + return a; + } - else{ - answer*= i; - } - return a; + return oddFactorial(a); } +*/ + +function oddFactorial(a){ + for(i=1, b=1; i<= a; i=i+2){ + b=b*i; + + } + return b; } /** @@ -124,6 +136,27 @@ const greeting = (name) => { * a single string and return it at the end of the function */ + function Chessboard(x){ + let string=""; + + for(q=0; q Date: Mon, 11 Nov 2019 13:16:06 -0500 Subject: [PATCH 6/6] did what i could for the chessboard exercise --- my-script.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/my-script.js b/my-script.js index 0d19953..4bb9d92 100644 --- a/my-script.js +++ b/my-script.js @@ -136,10 +136,11 @@ function oddFactorial(a){ * a single string and return it at the end of the function */ - function Chessboard(x){ + function chessboard(a){ + let dimenson=a; let string=""; - for(q=0; q