Loop Assignment - pattern generation
Hi Sir,
I am trying to do the Loop assignment - pattern generation for Write a JavaScript code so that numbers appear in following format,
for n=5. Input 'n' value from user.
I have got the below code working but doesnt have the spaces according to the picture. Please check and suggest.
My Code:
user = prompt("Type any number");
k = "";
for (i=1; i<=user; i ) {
j = i.toString();
document.write(k j "<br>");
k = k j;
}
k = k.toString();
for (x=user; x>0; x--) {
document.write(k.substr(0, (x-1)) "<br>");
}