Help me with this logic (newbie) [migrated]
- by Surendra
I need to generate a half pyramid number series with the entered starting number and the number of lines in a html page using Javascript and show the result in html page . I have done the Java scripting and stuff . What I don't get is the logic to it.
Take a look at this you may get an idea what I'm talking about:
Here is my function in Javascript that will be triggered on a button click function
doFunction(){
var enteredNumber=document.getElementById("start");
var lines=document.getElementById("lines");
var result;
for(i=0;i<=lines.value;i++) {
for(j=enteredNumber.value;j<=i;j++) { document.write(j + " " + " "); }
document.write("<br />");
}
}
Help me with the logic to print following order:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
There is a condition. I will specify $start and $lines.
If $start = 5 and $lines = 3 then output should be like:
5
5 6
5 6 7
I have had used the for loop , but that doesn't work if I give my own start number that is higher than the number of lines.
I actually need it done with Javascript, I have had done the necessary but I'm confused with the logic to generate such series (with the user given values) I had actually used two for loops to generate the regular number series like below 1 1 2 1 2 3 and so on.