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* \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);
}
104 changes: 102 additions & 2 deletions assets/js/shapes.js
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion assets/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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("------------------------------------")
Expand Down