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..979e0ac 100644 --- a/assets/js/shapes.js +++ b/assets/js/shapes.js @@ -1,31 +1,92 @@ function getLine(length) { - // TODO - write method definition here + var str = ""; + for(var i = 0; i < length; i++){ + str = str + "*"; + } + return str; } function getBox(width, height) { - // TODO - write method definition here + var str = ""; + for(var i = 0; i < height; i++){ + for(var j = 0; j < width; j++){ + str = str + "*"; + } + str = str + "\n"; + } + return str; } function getBottomLeftTriangle(length) { - // TODO - write method definition here + var str = ""; + for(var index = 1; index <= length; index++) { + for(var num = 0; num < index; num++) { + str = str + "*"; + } + str = str + "\n"; + } + return str.slice(0,-1); } function getUpperLeftTriangle(length) { - // TODO - write method definition here + var str = ""; + for(var index = length; index >= 1; index--) { + for(var num = 0; num < index; num++) { + str = str + "*"; + } + str = str + "\n"; + } + return str.slice(0,-1); } function getPyramid(length) { - // TODO - write method definition here + var str = ""; + for(var j = 1, i = 1, num = length-1; j <= length; j++, i=i+2, num--){ + var temp = num; + while(temp > 0){ + str = str + " "; + temp --; + } + temp = i; + while(temp > 0){ + str = str + "*"; + temp --; + } + temp = num; + while(temp > 0){ + str = str + " "; + temp --; + } + str = str + "\n"; + } + return str.slice(0,-1); } function getCheckerboard(width, height) { - // TODO - write method definition here + var str = ""; + for(var i = 0; i < height; i++){ + if(i%2 == 0) + var temp = 0; + else var temp = 1; + for(var j = 0; j < width; j++){ + if(temp == 0) { + temp = 1; + str = str + " "; + continue;} + else { + str = str + "*"; + temp = 0; + } + } + str = str + "\n"; + } + return str.slice(0,-1); } diff --git a/index.html b/index.html index 104b23b..c8d99ec 100644 --- a/index.html +++ b/index.html @@ -1,9 +1,5 @@ - - - - @@ -16,38 +12,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file