From 67565d5c57bd73ff38898e71f68ac5f400bef08e Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 29 Jun 2020 16:51:54 -0400 Subject: [PATCH 1/6] pushing exercises --- assets/js/footer-functions.js | 2 +- assets/js/shapes.js | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/assets/js/footer-functions.js b/assets/js/footer-functions.js index 42cc05b..a6ff491 100644 --- a/assets/js/footer-functions.js +++ b/assets/js/footer-functions.js @@ -24,7 +24,7 @@ function getBoxTests() { function getBottomLeftTriangleTests() { testGetBottomLeftTriangle("*", 1); testGetBottomLeftTriangle("*\n**", 2); - testGetBottomLeftTriangle("*\n**\n**", 3); + testGetBottomLeftTriangle("*\n**\n***", 3); } function getUpperLeftTriangleTests() { diff --git a/assets/js/shapes.js b/assets/js/shapes.js index e4351ba..c9682f2 100644 --- a/assets/js/shapes.js +++ b/assets/js/shapes.js @@ -1,22 +1,54 @@ function getLine(length) { - // TODO - write method definition here + var stars = ""; + for (var starLength=0; starLength < length; starLength++) { + stars = stars + "*"; + } + return stars; } function getBox(width, height) { // TODO - write method definition here + var stars = ""; + for(rows = 0; rows < height; rows++) { + for (columns = 0; columns < width; columns++) { + stars += "*"; + } + stars += "\n"; + } + return stars; } function getBottomLeftTriangle(length) { // TODO - write method definition here + var stars = ""; + for(i = 1; i <= length; i++) { + for (j = 0; j < i; j++) { + stars += "*"; + } + if (i != length) { + stars += "\n"; + } + } + return stars; } function getUpperLeftTriangle(length) { // TODO - write method definition here + var stars = ""; + for(i = 1; i <= length; i++) { + for (j = length; j < i; j--) { + stars += "*"; + } + if (i != length) { + stars += "\n"; + } + } + return stars; } From 8c0e778ceefc80ec0c15e07e9d7ae0fcf79bb9be Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 29 Jun 2020 23:56:49 -0400 Subject: [PATCH 2/6] All but one done. Need to clean up code --- assets/js/shapes.js | 59 ++++++++++++++++++++++++++++++++++++++------- index.html | 52 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 9 deletions(-) diff --git a/assets/js/shapes.js b/assets/js/shapes.js index c9682f2..481c958 100644 --- a/assets/js/shapes.js +++ b/assets/js/shapes.js @@ -7,11 +7,10 @@ function getLine(length) { } - function getBox(width, height) { // TODO - write method definition here var stars = ""; - for(rows = 0; rows < height; rows++) { + for(rows = 0; rows < height; rows++) { for (columns = 0; columns < width; columns++) { stars += "*"; } @@ -21,11 +20,10 @@ function getBox(width, height) { } - function getBottomLeftTriangle(length) { // TODO - write method definition here var stars = ""; - for(i = 1; i <= length; i++) { + for(i = 1; i <= length; i++) { for (j = 0; j < i; j++) { stars += "*"; } @@ -40,24 +38,67 @@ function getBottomLeftTriangle(length) { function getUpperLeftTriangle(length) { // TODO - write method definition here var stars = ""; - for(i = 1; i <= length; i++) { - for (j = length; j < i; j--) { + for(i = length; i >= 1; i--) { + if (i!=length) { + stars += "\n"; + } + for (j = 1; j <= i ; j++) { stars += "*"; + } + } + return stars; +} + + +function getPyramid(length) { + // TODO - write method definition here + var stars = ""; + var spacing = length; + var newPyramid = true; + for (i = 1; i <= length; i++) { + + for (j = 0; j < spacing -1; j++) { + stars += " "; + } + + for (k = 1; k <= i; k++) { + if (i == 1 && k==1 && newPyramid) { + stars += "*"; + spacing--; + + } else { + stars += "**"; + spacing--; + } } + + + if (i != length) { + if (!newPyramid) { + stars=stars.substring(0, stars.length - 1); + } stars += "\n"; + newPyramid = false; } } + if (stars.indexOf("*")) { + stars=stars.substring(0, stars.length - 1); + } return stars; } -function getPyramid(length) { - // TODO - write method definition here -} function getCheckerboard(width, height) { // TODO - write method definition here + } + + + + + + diff --git a/index.html b/index.html index 104b23b..bfe7688 100644 --- a/index.html +++ b/index.html @@ -1,23 +1,43 @@ + + + + + + + + + + + + + + + + + + + + @@ -26,28 +46,60 @@ + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + + + + + + + \ No newline at end of file From 72be7b18415666cdd71eed5cd06d9166d93dcc46 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 30 Jun 2020 00:59:56 -0400 Subject: [PATCH 3/6] updated next-to-last answer. Need to complete last answer --- assets/js/shapes.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/assets/js/shapes.js b/assets/js/shapes.js index 481c958..a6ad5e5 100644 --- a/assets/js/shapes.js +++ b/assets/js/shapes.js @@ -56,30 +56,28 @@ function getPyramid(length) { var spacing = length; var newPyramid = true; for (i = 1; i <= length; i++) { - for (j = 0; j < spacing -1; j++) { stars += " "; } - for (k = 1; k <= i; k++) { if (i == 1 && k==1 && newPyramid) { stars += "*"; - spacing--; - + spacing--; } else { stars += "**"; spacing--; } } - - - if (i != length) { if (!newPyramid) { stars=stars.substring(0, stars.length - 1); } + for (j = 0; j < length -1; j++) { + stars += " "; + stars += "\n"; newPyramid = false; + } } } if (stars.indexOf("*")) { @@ -88,10 +86,6 @@ function getPyramid(length) { return stars; } - - - - function getCheckerboard(width, height) { // TODO - write method definition here From 2e9c515cc13228775959f4dba9f76194dc539270 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 1 Jul 2020 17:24:53 -0400 Subject: [PATCH 4/6] updating files; starting back in --- assets/js/shapes.js | 59 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/assets/js/shapes.js b/assets/js/shapes.js index a6ad5e5..b8ac500 100644 --- a/assets/js/shapes.js +++ b/assets/js/shapes.js @@ -88,10 +88,69 @@ function getPyramid(length) { function getCheckerboard(width, height) { // TODO - write method definition here + var stars = ""; + var counter3 = 0; + var counter1_2; + for(rows = 0; rows < height-1; rows++) { + for (columns = 0; columns < width-1; columns++) { + counter3 ++; + if (counter3 % 3 == 0) { + stars += "* *\n"; + } else { + counter1_2 ++; + if (counter1_2 % 2 == 0) { + stars += "*\n * \n" + } else { + stars +=" *\n* " + } + + } + } + stars += "\n"; + } + return stars; +} + + + +/* + var stars = ""; + var spacing = length; + var diamondLevel = 0; + for (i = 1; i <= length; i++) { + for (j = 0; j < spacing -1; j++) { + stars += " "; + } + for (k = 1; k <= i; k++) { + if (i == 1 && k==1 && newPyramid) { + stars += "*"; + spacing--; + } else { + stars += "**"; + spacing--; + } + } + if (i != length) { + if (!newPyramid) { + stars=stars.substring(0, stars.length - 1); + } + for (j = 0; j < length -1; j++) { + stars += " "; + + stars += "\n"; + newPyramid = false; + } + } + } + if (stars.indexOf("*")) { + stars=stars.substring(0, stars.length - 1); + } + return stars; } +*/ From bd61e8e88db811a3d8662fcb74c180723f3f1b19 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 1 Jul 2020 19:06:03 -0400 Subject: [PATCH 5/6] finished shapes --- assets/js/shapes.js | 80 ++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 48 deletions(-) diff --git a/assets/js/shapes.js b/assets/js/shapes.js index b8ac500..d2dc20a 100644 --- a/assets/js/shapes.js +++ b/assets/js/shapes.js @@ -88,6 +88,30 @@ function getPyramid(length) { function getCheckerboard(width, height) { // TODO - write method definition here + var stars = ""; + var pyrHeight; + for (pyrHeight = 1; pyrHeight <= height; pyrHeight++) { + if (width < 3){ + if (pyrHeight % 2 != 0) { + stars += " *"; + } else { + stars += "* "; + } + } + if (width >= 3) { + if (pyrHeight % 2 != 0) { + stars += " * "; + } else { + stars += "* *"; + } + } + stars +="\n"; + } + return stars; +} + + /* === + var stars = ""; var counter3 = 0; var counter1_2; @@ -101,57 +125,17 @@ function getCheckerboard(width, height) { if (counter1_2 % 2 == 0) { stars += "*\n * \n" } else { - stars +=" *\n* " + if (height < 3) { + stars +=" *\n* " + } else { + stars += " * \n*" + } } } } stars += "\n"; - } - return stars; -} - - - - -/* - var stars = ""; - var spacing = length; - var diamondLevel = 0; - for (i = 1; i <= length; i++) { - for (j = 0; j < spacing -1; j++) { - stars += " "; - } - for (k = 1; k <= i; k++) { - if (i == 1 && k==1 && newPyramid) { - stars += "*"; - spacing--; - } else { - stars += "**"; - spacing--; - } - } - if (i != length) { - if (!newPyramid) { - stars=stars.substring(0, stars.length - 1); - } - for (j = 0; j < length -1; j++) { - stars += " "; - - stars += "\n"; - newPyramid = false; - } - } - } - if (stars.indexOf("*")) { - stars=stars.substring(0, stars.length - 1); - } - return stars; -} - - -*/ - - - + } */ +// return stars; +//} From 7555234c7ba8098b8daa4b0ddda8bef15236d5e4 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 13 Jul 2020 00:56:25 -0400 Subject: [PATCH 6/6] tweaks and touchups --- assets/js/shapes.js | 36 +++++------------------------------- 1 file changed, 5 insertions(+), 31 deletions(-) diff --git a/assets/js/shapes.js b/assets/js/shapes.js index d2dc20a..62179ea 100644 --- a/assets/js/shapes.js +++ b/assets/js/shapes.js @@ -62,7 +62,10 @@ function getPyramid(length) { for (k = 1; k <= i; k++) { if (i == 1 && k==1 && newPyramid) { stars += "*"; - spacing--; + spacing--; + if (length >= 3) { + stars += " "; + } } else { stars += "**"; spacing--; @@ -77,6 +80,7 @@ function getPyramid(length) { stars += "\n"; newPyramid = false; + break; } } } @@ -109,33 +113,3 @@ function getCheckerboard(width, height) { } return stars; } - - /* === - - var stars = ""; - var counter3 = 0; - var counter1_2; - for(rows = 0; rows < height-1; rows++) { - for (columns = 0; columns < width-1; columns++) { - counter3 ++; - if (counter3 % 3 == 0) { - stars += "* *\n"; - } else { - counter1_2 ++; - if (counter1_2 % 2 == 0) { - stars += "*\n * \n" - } else { - if (height < 3) { - stars +=" *\n* " - } else { - stars += " * \n*" - } - } - - } - } - stars += "\n"; - } */ -// return stars; -//} -