Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions assets/js/footer-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function getBoxTests() {
function getBottomLeftTriangleTests() {
testGetBottomLeftTriangle("*", 1);
testGetBottomLeftTriangle("*\n**", 2);
testGetBottomLeftTriangle("*\n**\n**", 3);
testGetBottomLeftTriangle("*\n**\n***", 3);
}

function getUpperLeftTriangleTests() {
Expand All @@ -42,7 +42,7 @@ function getPyramidTests() {


function getCheckerboardTests() {
testGetCheckerboard(" *\n* ", 2, 2);
testGetCheckerboard(" * \n* *\n * ", 3, 3);
testGetCheckerboard(" *\n* \n", 2, 2);
testGetCheckerboard(" * \n* *\n * \n", 3, 3);
testGetCheckerboard(" * \n* *\n * \n* *\n", 3, 4);
}
143 changes: 133 additions & 10 deletions assets/js/shapes.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,154 @@
/* Get a Simple Line
length : length of the line
return : String that resembles a line consisting of *
*/
function getLine(length) {
// TODO - write method definition here
if (length < 0) {
throw new Error("Illegal arguement - length needs to be greater than 0");
}

var line = "";
while (length > 0) {
line += "*";
length--;
}
return line;
}

/* Get a Box
width : width of box
height : height of box
return : String that resembles a box that consists of *
*/
function getBox(width, height) {
if (width < 0) {
throw new Error("Illegal arguement - width needs to be greater than 0");
} else if (height < 0) {
throw new Error("Illegal arguement - height needs to be greater than 0");
}

var line = new String();
for (var heightIndex = 0; height > heightIndex; heightIndex++) {
line += getLine(width);

function getBox(width, height) {
// TODO - write method definition here
//All Boxes will have a \n at the end of each line (even last)
line += "\n";
}
return line;
}



/* Get a Right Triangle that Bottom is located bottom left
length : of longest side of triangle
return : String that resembles a right triangle
*/
function getBottomLeftTriangle(length) {
// TODO - write method definition here
}
if (length < 0) {
throw new Error("length needs to be greater than 0");
}
var triangle = new String();
var lineNumber = 1;
while (length >= lineNumber) {
triangle += getLine(lineNumber);


//Make sure every row besides last gets a new line
if (lineNumber != length) {
triangle += "\n";
}
lineNumber++;
}
return triangle;
}

/* Get a Right Triangle that Bottom is located top left
length : of longest side of triangle
return : String that resembles a right triangle
*/
function getUpperLeftTriangle(length) {
// TODO - write method definition here
if (length < 0) {
throw new Error("Illegal arguement - length needs to be greater than 0");
}
var triangle = new String();
var lineNumber = length;
while (lineNumber > 0) {
triangle += getLine(lineNumber);
lineNumber--;

//Make sure every row besides last gets a new line
if (lineNumber != 0) {
triangle += "\n";
}
}
return triangle;
}


/* Get a Pyramid whose row = length and longest col = length * 2 - 1
length : amount of rows the pyramid will have
return : String that resembles a pyramid

PS: I know there's an easier way to this but I couldn't think of it at this time.
#TODO come back and figure out pattern to combine three inner for loops into one loop
*/
function getPyramid(length) {
// TODO - write method definition here
}
if (length < 0) {
throw new Error("Illegal arguement - length needs to be greater than 0");
}
col = length * 2 - 1;
row = length;
var amountStars = 1;
var pyramid = new String();
for (var j = 0; row > j; j++) {

//Calculate amount spaces on row
var amountSpaces = Math.floor((col - amountStars) / 2);

//Add first set of spaces
for (var i = 0; amountSpaces > i; i++) {
pyramid += " ";
}

//Add Stars
for (var i = 0; amountStars > i; i++) {
pyramid += "*";
}

//Add second set of spaces
for (var i = 0; amountSpaces > i; i++) {
pyramid += " ";
}

//Make sure every row besides last gets a new line
if(j != row - 1){
pyramid += "\n";
}
amountStars += 2;
}
return pyramid;
}

/* Get a Checkerboard with "odd" cells = "*" and "even" = " "
width : width of the checkerboard
height : height of the checkerboard
return : String that resembles a checkerboard type pattern.
*/
function getCheckerboard(width, height) {
// TODO - write method definition here
if (width < 0) {
throw new Error("Illegal arguement - width needs to be greater than 0");
} else if (height < 0) {
throw new Error("Illegal arguement - height needs to be greater than 0");
}

var checkerboard = new String();
for (var heightIndex = 0; height > heightIndex; heightIndex++) {
for (var widthIndex = 0; width > widthIndex; widthIndex++) {
//Depending on Cell position if x y added together is even than space otherwise *
checkerboard += ((heightIndex + widthIndex) % 2 == 0) ? " " : "*";
}

//Every line gets a \n
checkerboard += "\n";
}
return checkerboard;
}
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<script type="text/javascript" src="./assets/js/utils.js"></script>
<script type="text/javascript" src="./assets/js/shapes.js"></script>
<script type="text/javascript" src="./assets/js/header-functions.js"></script>

</head> <!-- header ends here -->
<!-- ----------------------------------------------------------------- -->
<!-- ----------------------------------------------------------------- -->
Expand Down