Created
November 21, 2017 14:31
-
-
Save revazi/0299d90448df207dce133a33e825036b to your computer and use it in GitHub Desktop.
node.js console app for generating pyramid.
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
var readline = require('readline'); | |
var rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
rl.question("What's the pyramid size? ", function(answer) { | |
var size = parseInt(answer); | |
var tmpString = ""; | |
if (size) { | |
for (var i = size, s = 1; i > 0; i--, s+=2) { | |
tmpString = ""; | |
tmpString = new Array(i).join(" "); | |
tmpString += s == 1 ? 'x' : new Array(s+1).join("x"); | |
console.log(tmpString); | |
} | |
} else { | |
console.log("Warning: pyramid size should be an Int."); | |
} | |
rl.close(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment