Skip to content

Instantly share code, notes, and snippets.

@revazi
Created November 21, 2017 14:31
Show Gist options
  • Save revazi/0299d90448df207dce133a33e825036b to your computer and use it in GitHub Desktop.
Save revazi/0299d90448df207dce133a33e825036b to your computer and use it in GitHub Desktop.
node.js console app for generating pyramid.
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