From 45fe01a457d87af23fabc82fa65d6d9c96c64bf3 Mon Sep 17 00:00:00 2001 From: Marcus Katalenas Date: Mon, 29 Jun 2020 15:15:16 -0400 Subject: [PATCH 1/6] Finished code for both getLine and getBox --- assets/js/shapes.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/assets/js/shapes.js b/assets/js/shapes.js index e4351ba..1e87fab 100644 --- a/assets/js/shapes.js +++ b/assets/js/shapes.js @@ -1,11 +1,30 @@ function getLine(length) { - // TODO - write method definition here + + var line = ""; + for(var count = 0; count < length; count++){ + line += "*"; + } + return line; } function getBox(width, height) { - // TODO - write method definition here + + var hCount = 0; + var wCount = 0; + var box = ""; + while(hCount < height){ + wCount = 0; + while(wCount < width){ + box += "*" + wCount++; + } + box += "\n"; + wCount = 0; + hCount++; + } + return box; } From 16b54f309d6500de00618453138fbbd9827297e3 Mon Sep 17 00:00:00 2001 From: Marcus Katalenas Date: Mon, 29 Jun 2020 15:33:20 -0400 Subject: [PATCH 2/6] Finished getCheckerboard code to pass the test cases --- assets/js/shapes.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/assets/js/shapes.js b/assets/js/shapes.js index 1e87fab..87242ac 100644 --- a/assets/js/shapes.js +++ b/assets/js/shapes.js @@ -46,5 +46,33 @@ function getPyramid(length) { function getCheckerboard(width, height) { - // TODO - write method definition here + var hCount = 0; + var wCount = 0; + var lineCount = 0; + var checkerBoard = ""; + var currentLineCharCount = 0; + + for(var hCount = 0; hCount < height; hCount++){ + for(wCount = 0; wCount < width; wCount++){ + if(hCount % 2 == 0){ + if(wCount % 2 == 0){ + checkerBoard += " "; + } + else{ + checkerBoard += "*"; + } + } + else{ + if(wCount % 2 == 0){ + checkerBoard += "*"; + } + else{ + checkerBoard += " "; + } + } + } + checkerBoard += "\n"; + } + + return checkerBoard; } From e433a90838745b129a0d89582978b26f8ddb5852 Mon Sep 17 00:00:00 2001 From: Marcus Katalenas Date: Mon, 29 Jun 2020 15:39:53 -0400 Subject: [PATCH 3/6] Finished getBottomeLeftTriangle --- assets/js/shapes.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/assets/js/shapes.js b/assets/js/shapes.js index 87242ac..2d951ee 100644 --- a/assets/js/shapes.js +++ b/assets/js/shapes.js @@ -31,6 +31,19 @@ function getBox(width, height) { function getBottomLeftTriangle(length) { // TODO - write method definition here + var count = 0; + var numOfStarsForLine = 1; + var bottomeLeftTriangle = ""; + while(count < length){ + for(var starCount = 0; starCount < numOfStarsForLine; starCount++){ + bottomeLeftTriangle += "*"; + } + + bottomeLeftTriangle += "\n"; + count++; + numOfStarsForLine++; + } + return bottomeLeftTriangle; } From 268ac59f367d532d7da35726007174cd4d0a3fc7 Mon Sep 17 00:00:00 2001 From: Marcus Katalenas Date: Mon, 29 Jun 2020 15:54:41 -0400 Subject: [PATCH 4/6] Finished the getPyramid function --- assets/js/shapes.js | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/assets/js/shapes.js b/assets/js/shapes.js index 2d951ee..92963fc 100644 --- a/assets/js/shapes.js +++ b/assets/js/shapes.js @@ -33,28 +33,61 @@ function getBottomLeftTriangle(length) { // TODO - write method definition here var count = 0; var numOfStarsForLine = 1; - var bottomeLeftTriangle = ""; + var bottomLeftTriangle = ""; while(count < length){ for(var starCount = 0; starCount < numOfStarsForLine; starCount++){ - bottomeLeftTriangle += "*"; + bottomLeftTriangle += "*"; } - bottomeLeftTriangle += "\n"; + bottomLeftTriangle += "\n"; count++; numOfStarsForLine++; } - return bottomeLeftTriangle; + return bottomLeftTriangle; } function getUpperLeftTriangle(length) { // TODO - write method definition here + var count = 0; + var numOfStarsForLine = length; + var upperLeftTriangle = ""; + while(count < length){ + for(var starCount = 0; starCount < numOfStarsForLine; starCount++){ + upperLeftTriangle += "*"; + } + + upperLeftTriangle += "\n"; + count++; + numOfStarsForLine--; + } + return upperLeftTriangle; } -function getPyramid(length) { - // TODO - write method definition here +function getPyramid(length){ + var count = 0; + var starsPerLine = 1; + var pyramid = ""; + while(count < length){ + if(length - count == 3){ + pyramid += " "; + } + else if(length - count == 2){ + pyramid += " "; + } + else{ + + } + for(var starCount = 0; starCount < starsPerLine; starCount++){ + pyramid += "*"; + } + pyramid += "\n"; + starsPerLine += 2; + count++; + } + return pyramid; } From 40b315f8a83904e8de9e55d8607eeeb8f6684921 Mon Sep 17 00:00:00 2001 From: Marcus Katalenas Date: Mon, 29 Jun 2020 16:09:29 -0400 Subject: [PATCH 5/6] Removed blank else statment --- assets/js/shapes.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/assets/js/shapes.js b/assets/js/shapes.js index 92963fc..76e673b 100644 --- a/assets/js/shapes.js +++ b/assets/js/shapes.js @@ -76,9 +76,6 @@ function getPyramid(length){ } else if(length - count == 2){ pyramid += " "; - } - else{ - } for(var starCount = 0; starCount < starsPerLine; starCount++){ pyramid += "*"; @@ -119,6 +116,5 @@ function getCheckerboard(width, height) { } checkerBoard += "\n"; } - return checkerBoard; } From 01d4296a80408113673da038e7a1eb5ff15dfa67 Mon Sep 17 00:00:00 2001 From: Marcus Katalenas Date: Mon, 29 Jun 2020 16:28:33 -0400 Subject: [PATCH 6/6] Removed unused vars --- assets/js/shapes.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/assets/js/shapes.js b/assets/js/shapes.js index 76e673b..5ec3a7f 100644 --- a/assets/js/shapes.js +++ b/assets/js/shapes.js @@ -91,9 +91,7 @@ function getPyramid(length){ function getCheckerboard(width, height) { var hCount = 0; var wCount = 0; - var lineCount = 0; var checkerBoard = ""; - var currentLineCharCount = 0; for(var hCount = 0; hCount < height; hCount++){ for(wCount = 0; wCount < width; wCount++){