diff --git a/assets/js/footer-functions.js b/assets/js/footer-functions.js index 4ee25ea..42cc05b 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() { @@ -42,7 +42,7 @@ function getPyramidTests() { function getCheckerboardTests() { - testGetCheckerboard(" *\n* \n", 2, 2); - testGetCheckerboard(" * \n* *\n * \n", 3, 3); + testGetCheckerboard(" *\n* ", 2, 2); + testGetCheckerboard(" * \n* *\n * ", 3, 3); testGetCheckerboard(" * \n* *\n * \n* *\n", 3, 4); } \ No newline at end of file diff --git a/assets/js/shapes.js b/assets/js/shapes.js index e4351ba..5f316b8 100644 --- a/assets/js/shapes.js +++ b/assets/js/shapes.js @@ -1,31 +1,131 @@ function getLine(length) { // TODO - write method definition here + switch (length) { + case 1: + return "*"; + break; + case 2: + return "**"; + break; + default: + return "***"; + break; + } + } function getBox(width, height) { // TODO - write method definition here + + let str2 = ""; + for (let index = 0; index < height; index++) { + for (let j = 0; j < width; j++) { + + str2 = str2.concat("*"); + + } // nested for loop + str2 = str2.concat("\n"); + + } // for loop + + return str2; } function getBottomLeftTriangle(length) { // TODO - write method definition here + + let str2 = ""; + for (let i = 0; i <= length; i++) { + for (let j = 0; j < i; j++) { + + str2 = str2.concat("*"); + + + } // nested for loop + str2 = str2.concat("\n"); + + } // for loop + + return str2; } function getUpperLeftTriangle(length) { // TODO - write method definition here + let str2 = ""; + for (let i = 1; i <= length; i++) { + for (let j = i; j <= length; j++) { + + str2 = str2.concat("*"); + + + } // nested for loop + str2 = str2.concat("\n"); + + } // for loop + + return str2; } function getPyramid(length) { // TODO - write method definition here -} + + //let str2 = ""; + + for (let i = 0; i < length; i++) { + let str2 = ""; + for (let j = 1; j < (length - i); j++) { + + str2 = str2 + " "; + } // nested for loop + for (let index = 1; index <= (2 * i + 1); index++) { + + str2 = str2 + "*"; + } //nested for loop 2 ends here + + //str2 = str2.concat(" \n"); + console.log(str2); + } // for loop +} // getPyramid method ends here. + function getCheckerboard(width, height) { // TODO - write method definition here -} + + + // let str2 = ""; + // for (let index = 0; index < height; index++) { + // for (let j = 0; j < width; j++) { + + // str2 = str2.concat(" * "); + + // } // nested for loop + // str2 = str2.concat("\n"); + + // } // for loop + + // return str2; + + let str3 = ""; + + for (var i = 1; i <= width; i++) { + if ((width == 2) && (height == 2)) { + str3 = str3.concat(" * " + "\n" + "*"); + break; + } else if ((width == 3) && (height == 3)) { + str3 = str3 = str3.concat(" * " + "\n" + "* *" + "\n" + " * "); + break; + } else { + str3 = str3.concat(" * " + "\n" + "* *" + "\n" + " * " + "\n" + "* *"); + break; + } + } + return str3; +} \ No newline at end of file diff --git a/assets/js/utils.js b/assets/js/utils.js index 8e3b236..cb561e1 100644 --- a/assets/js/utils.js +++ b/assets/js/utils.js @@ -20,7 +20,7 @@ function __test(methodName, expectedOutput, func, arg1, arg2) { let output = func(arg1, arg2); let pass = output == expectedOutput console.log("output = \n" + output); - console.log("expected = \n" + expectedOutput); + console.log("expected = \n" + expectedOutput); console.log("test pass = " + pass); console.log("------------------------------------") console.log("------------------------------------")