How to print the below pattern using javascript
n = 4
1
2 5
3 6 8
4 7 9 10
I tried the below code but it print the incremental number in row
const pattern = (n) => {
let count = 1;
for (let row = 0; row < n; row++) {
for (let col = 0; col <= row; col++) {
document.write(count + " ");
count++;
}
document.write("<br/>");
}
};
pattern(4);
but the expectation is to print incremental number in col
3
Answers
You are almost on goal.. you just a small fix: pretty simple and basic
and as your example
instead of
console.log
you can do