We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
var sp1=" ";
var h = "#";
for(k=n;k>0;k--){
//console.log(k);
switch (k)
{
case 1:
console.log(h+h+h+h+h+h);
break;
case 2:
console.log(sp1+h+h+h+h+h);
break;
case 3:
console.log(sp1+sp1+h+h+h+h);
break;
case 4:
console.log(sp1+sp1+sp1+h+h+h);
break;
case 5:
console.log(sp1+sp1+sp1+sp1+h+h);
break;
case 6:
console.log(sp1+sp1+sp1+sp1+sp1+h);
break;
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Staircase
You are viewing a single comment's thread. Return to all comments →
var sp1=" "; var h = "#"; for(k=n;k>0;k--){ //console.log(k);
switch (k) { case 1: console.log(h+h+h+h+h+h);
break;
case 2: console.log(sp1+h+h+h+h+h); break; case 3: console.log(sp1+sp1+h+h+h+h); break; case 4: console.log(sp1+sp1+sp1+h+h+h); break; case 5: console.log(sp1+sp1+sp1+sp1+h+h); break; case 6: console.log(sp1+sp1+sp1+sp1+sp1+h); break; } }