From 38053569b1c87441fcecb2b172fc8117098d9298 Mon Sep 17 00:00:00 2001 From: monicadeshmukh Date: Mon, 29 Jun 2020 16:44:28 -0400 Subject: [PATCH 1/2] getline, getbottomlefttraingle, getupperlefttraingle, getpyramid --- assets/js/shapes.js | 87 +++++++++++++++++++++++++++++++++++++++++++++ index.html | 1 + 2 files changed, 88 insertions(+) diff --git a/assets/js/shapes.js b/assets/js/shapes.js index e4351ba..6e2d10e 100644 --- a/assets/js/shapes.js +++ b/assets/js/shapes.js @@ -1,31 +1,118 @@ function getLine(length) { // TODO - write method definition here + var output = ""; + while(length !=0) + { + output += "*"; + length--; + } + return output; } function getBox(width, height) { // TODO - write method definition here + var output = ""; + var w = width; + while(height > 0) + { + while(w > 0) + { + output += "*"; + w--; + } + output += "\n"; + height--; + w = width; + } + return output; + } function getBottomLeftTriangle(length) { // TODO - write method definition here + var output = ""; + var count = 1; + while(length > 0) + { + for (var cnt = count; cnt > 0; cnt--) + { + output += "*"; + } + if (length != 1) + output += "\n"; + count++; + length--; + + } + return output; } function getUpperLeftTriangle(length) { // TODO - write method definition here + var output = ""; + var count = length; + while(length > 0) + { + for (var cnt = count; cnt > 0; cnt--) + { + output += "*"; + } + if (length != 1) + output += "\n"; + count--; + length--; + + } + return output; } + function getPyramid(length) { // TODO - write method definition here + var output = ""; + var printSpace = length - 1; + var printAsterics = length - printSpace; + while (length > 0) + { + /* for(var count = 0; count < length; count++) + {*/ + for (var printS = printSpace; printS > 0; printS--) + { + output += " "; + } + for (var printA = printAsterics; printA > 0; printA--) + { + output += "*"; + } + for (var printS = printSpace; printS > 0; printS--) + { + output += " "; + } + /* }*/ + if (length != 1) + output += "\n"; + length--; + printSpace--; + printAsterics += 2; + + } + + return output; } + function getCheckerboard(width, height) { // TODO - write method definition here + var output = ""; + /* print width no. of stars in two lines. print a total of height no. of lines. */ + output = parseInt(11/2); + return output; } diff --git a/index.html b/index.html index 104b23b..b242827 100644 --- a/index.html +++ b/index.html @@ -38,6 +38,7 @@ +