Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(num){
- num = Number(num);
- let isNumOdd = num % 2 == 0; // true / false
- let roof = Math.floor((num + 1) / 2); // defines how much rows for the roof
- let stars;
- let subtract;
- // roof
- if(isNumOdd){
- console.log('-'.repeat((num - 2) / 2) + '**' + '-'.repeat((num - 2) / 2));
- stars = 2;
- } else {
- console.log('-'.repeat((num - 1) / 2) + '*' + '-'.repeat((num - 1) / 2));
- stars = 1;
- }
- for(let i = 1; i < roof; i++) {
- stars += 2;
- subtract = (num - stars) / 2;
- console.log('-'.repeat(subtract) + '*'.repeat(stars) + '-'.repeat(subtract));
- }
- // house
- let houseRows = num - roof;
- for(let i = 1; i <= houseRows; i++) {
- console.log('|' + '*'.repeat(num - 2) + '|');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement