Created
August 16, 2019 09:50
-
-
Save Nocks/f39752eeaaddfb8281be2668552c49cb to your computer and use it in GitHub Desktop.
For this quiz, you're going to create a function called buildTriangle() that will accept an input (the triangle at its widest width) and will return the string representation of a triangle.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Programming Quiz: Build A Triangle (5-3) | |
*/ | |
// creates a line of * for a given length | |
function makeLine(length) { | |
var line = ""; | |
for (var j = 1; j <= length; j++) { | |
line += "* "; | |
} | |
return line + "\n"; | |
} | |
// main triangle builder | |
function buildTriangle(widestWidth) { | |
if (widestWidth > 2) { | |
var triangleLine = ""; | |
for (var i = 1; i < widestWidth; i++) { | |
triangleLine += makeLine(i); | |
} | |
return triangleLine; | |
} else { | |
return "Widest width of the triangle must be more than 2."; | |
} | |
} | |
console.log(buildTriangle(10)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment