Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function printFigure([num]) {
- num = Number(num);
- if (!(num >= 2 && num <= 200)){
- return
- }
- let repeatPlus = `-`.repeat(num-2);
- let repeatSpace = ` `.repeat(num-2);
- let verticalLines = num % 2 == 0 ? num / 2 - 2 : num / 2 - 1;
- verticalLines = Math.floor(verticalLines);
- if(num == 2)
- return console.log(`+${repeatPlus}+${repeatPlus}+`);
- console.log(`+${repeatPlus}+${repeatPlus}+`);
- for (let i = 0; i < verticalLines; i++) {
- console.log(`|${repeatSpace}|${repeatSpace}|`)
- }
- console.log(`+${repeatPlus}+${repeatPlus}+`);
- for (let i = 0; i < verticalLines; i++) {
- console.log(`|${repeatSpace}|${repeatSpace}|`)
- }
- console.log(`+${repeatPlus}+${repeatPlus}+`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement