From 57c6152fce32f4e98b2cb36666f6ff7a5f2bfe90 Mon Sep 17 00:00:00 2001 From: Emmanuel Orubele Date: Mon, 29 Jun 2020 23:48:10 -0400 Subject: [PATCH 1/3] final changes to file --- assets/js/footer-functions.js | 6 +-- assets/js/shapes.js | 88 ++++++++++++++++++++++++++++++++++- assets/js/utils.js | 2 +- 3 files changed, 91 insertions(+), 5 deletions(-) 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..f531d68 100644 --- a/assets/js/shapes.js +++ b/assets/js/shapes.js @@ -1,31 +1,117 @@ 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 = 1; i <= length; i++) { + for (let j = 0; j < (length - i); j++) { + + str2 = str2.concat("\n"); + } // nested for loop + for (let index = 1; index <= i; index++) { + + str2 = str2.concat("*"); + } + + str2 = str2.concat("\n"); + } // for loop + return str2; } + function getCheckerboard(width, height) { // TODO - write method definition here -} + + + let str2 = ""; + + for (let i = 1; i <= length; i++) { + for (let j = 0; j < (length - i); j++) { + + str2 = str2.concat("\n"); + } // nested for loop + for (let index = 1; index <= i; index++) { + + str2 = str2.concat("*"); + } + + str2 = str2.concat("\n"); + } // for loop + return str2; +} \ 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("------------------------------------") From 365573337bf8ef1f75aab29d6d8c7ed2986872a7 Mon Sep 17 00:00:00 2001 From: Emmanuel Orubele Date: Tue, 30 Jun 2020 10:38:28 -0400 Subject: [PATCH 2/3] finished checkerbox JS file --- assets/js/shapes.js | 47 +++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/assets/js/shapes.js b/assets/js/shapes.js index f531d68..435ca49 100644 --- a/assets/js/shapes.js +++ b/assets/js/shapes.js @@ -79,19 +79,19 @@ function getPyramid(length) { let str2 = ""; for (let i = 1; i <= length; i++) { - for (let j = 0; j < (length - i); j++) { + for (let j = 1; j < (length - 1); j++) { - str2 = str2.concat("\n"); + str2 = str2.concat("\n "); } // nested for loop - for (let index = 1; index <= i; index++) { + for (let index = 1; index <= (i + 1); index++) { - str2 = str2.concat("*"); - } + str2 = str2.concat(" *"); + } //nested for loop 2 ends here str2 = str2.concat("\n"); } // for loop return str2; -} +} // getPyramid method ends here. @@ -99,19 +99,32 @@ function getCheckerboard(width, height) { // TODO - write method definition here - let str2 = ""; + // let str2 = ""; + // for (let index = 0; index < height; index++) { + // for (let j = 0; j < width; j++) { - for (let i = 1; i <= length; i++) { - for (let j = 0; j < (length - i); j++) { + // str2 = str2.concat(" * "); - str2 = str2.concat("\n"); - } // nested for loop - for (let index = 1; index <= i; index++) { + // } // nested for loop + // str2 = str2.concat("\n"); - str2 = str2.concat("*"); - } + // } // for loop - str2 = str2.concat("\n"); - } // for loop - return str2; + // 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 From c8c83ea46cd27fed3bce29ab6574174efd5699b0 Mon Sep 17 00:00:00 2001 From: Emmanuel Orubele Date: Tue, 30 Jun 2020 11:09:26 -0400 Subject: [PATCH 3/3] Finished pyramid changes --- assets/js/shapes.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/assets/js/shapes.js b/assets/js/shapes.js index 435ca49..5f316b8 100644 --- a/assets/js/shapes.js +++ b/assets/js/shapes.js @@ -76,21 +76,22 @@ function getUpperLeftTriangle(length) { function getPyramid(length) { // TODO - write method definition here - let str2 = ""; + //let str2 = ""; - for (let i = 1; i <= length; i++) { - for (let j = 1; j < (length - 1); j++) { + for (let i = 0; i < length; i++) { + let str2 = ""; + for (let j = 1; j < (length - i); j++) { - str2 = str2.concat("\n "); + str2 = str2 + " "; } // nested for loop - for (let index = 1; index <= (i + 1); index++) { + for (let index = 1; index <= (2 * i + 1); index++) { - str2 = str2.concat(" *"); + str2 = str2 + "*"; } //nested for loop 2 ends here - str2 = str2.concat("\n"); + //str2 = str2.concat(" \n"); + console.log(str2); } // for loop - return str2; } // getPyramid method ends here.