diff --git a/assets/js/footer-functions.js b/assets/js/footer-functions.js index 42cc05b..ea4906e 100644 --- a/assets/js/footer-functions.js +++ b/assets/js/footer-functions.js @@ -5,44 +5,38 @@ getUpperLeftTriangleTests(); getPyramidTests(); getCheckerboardTests(); - - - function getLineTests() { - testGetLine("*", 1); - testGetLine("**", 2); - testGetLine("***", 3); + testGetLine("*", 1); + testGetLine("**", 2); + testGetLine("***", 3); } - function getBoxTests() { - testGetBox("*\n", 1, 1); - testGetBox("**\n**\n", 2, 2); - testGetBox("***\n***\n***\n***\n", 3, 4); + testGetBox("*\n", 1, 1); + testGetBox("**\n**\n", 2, 2); + testGetBox("***\n***\n***\n***\n", 3, 4); } function getBottomLeftTriangleTests() { - testGetBottomLeftTriangle("*", 1); - testGetBottomLeftTriangle("*\n**", 2); - testGetBottomLeftTriangle("*\n**\n**", 3); + testGetBottomLeftTriangle("*\n", 1); + testGetBottomLeftTriangle("*\n**\n", 2); + testGetBottomLeftTriangle("*\n**\n***\n", 3); } function getUpperLeftTriangleTests() { - testGetUpperLeftTriangle("*", 1); - testGetUpperLeftTriangle("**\n*", 2); - testGetUpperLeftTriangle("***\n**\n*", 3); + testGetUpperLeftTriangle("*\n", 1); + testGetUpperLeftTriangle("**\n*\n", 2); + testGetUpperLeftTriangle("***\n**\n*\n", 3); } - function getPyramidTests() { - testGetPyramid("*", 1); - testGetPyramid(" * \n***", 2); - testGetPyramid(" * \n *** \n*****", 3); + testGetPyramid("*", 1); + testGetPyramid(" * \n***", 2); + testGetPyramid(" * \n *** \n*****", 3); } - function getCheckerboardTests() { - testGetCheckerboard(" *\n* ", 2, 2); - testGetCheckerboard(" * \n* *\n * ", 3, 3); - testGetCheckerboard(" * \n* *\n * \n* *\n", 3, 4); -} \ No newline at end of file + testGetCheckerboard(" *\n* \n", 2, 2); + testGetCheckerboard(" * \n* *\n *\n ", 3, 3); + testGetCheckerboard(" * \n* *\n * \n* *\n", 3, 4); +} diff --git a/assets/js/shapes.js b/assets/js/shapes.js index e4351ba..445e462 100644 --- a/assets/js/shapes.js +++ b/assets/js/shapes.js @@ -1,31 +1,109 @@ function getLine(length) { - // TODO - write method definition here + let output = ""; + let iterationCounter = 0; + for (iterationCounter; iterationCounter < length; iterationCounter++) { + output += "*"; + } + return output; } - - function getBox(width, height) { - // TODO - write method definition here -} - + let output = ""; + let iterationCounter; + let iterationCounter_2; + for (iterationCounter = 0; iterationCounter < height; iterationCounter++) { + for ( + iterationCounter_2 = 0; + iterationCounter_2 < width; + iterationCounter_2++ + ) { + output += "*"; + } + output += "\n"; + } + return output; +} function getBottomLeftTriangle(length) { - // TODO - write method definition here + let iterationCounter; + let iterationCounter_2; + let output = ""; + for (iterationCounter = 1; iterationCounter <= length; iterationCounter++) { + for ( + iterationCounter_2 = 0; + iterationCounter_2 < iterationCounter; + iterationCounter_2++ + ) { + output += "*"; + } + output += "\n"; + } + return output; } - function getUpperLeftTriangle(length) { - // TODO - write method definition here -} + let output = ""; + let iterationCounter; + let iterationCounter_2; + for (iterationCounter = length; iterationCounter >= 1; iterationCounter--) { + for ( + iterationCounter_2 = length - 1; + iterationCounter_2 >= length - iterationCounter; + iterationCounter_2-- + ) { + output += "*"; + } + output += "\n"; + } + return output; +} function getPyramid(length) { - // TODO - write method definition here + let shape=""; + let iterationCounter; + let iterationCounter_2; + let iteration_Counter_3; + let line; + if (length ==0 || length==1) return getLine(length); + for (iterationCounter=1; iterationCounter<=length;iterationCounter++){ + line = ""; + for (iterationCounter_2=1 ;iterationCounter_2<=length;iterationCounter_2++){ + line +=" "; + + } + for (iteration_Counter_3=1;iteration_Counter_3<=iterationCounter+2; iteration_Counter_3++{ + line+="*"; + shape+= line + "\n"; + } + } + return shape; } + function getCheckerboard(width, height) { - // TODO - write method definition here + let output=""; + + let iterationCounter; + let iterationCounter_2; + let iteration_Counter_3=1; + + for( iterationCounter = 1; iterationCounter <= height; iterationCounter++) { + for(iterationCounter_2 = width; iterationCounter_2 > 0; iterationCounter_2--) { + if(iteration_Counter_3 % 2 == 0) { + output += "*"; + } + else { + output += " "; + } + iteration_Counter_3++; + } + if(width % 2 == 0) { iteration_Counter_3++; } + output += "\n"; + } + return output; + }