Back to Freecodecamp

Challenge 78: Integer Sequence

curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68d30845cc08266018fc46be.md

latest878 B
Original Source

--description--

Given a positive integer, return a string with all of the integers from 1 up to, and including, the given number, in numerical order.

For example, given 5, return "12345".

--hints--

sequence(5) should return "12345".

js
assert.equal(sequence(5), "12345");

sequence(10) should return "12345678910".

js
assert.equal(sequence(10), "12345678910");

sequence(1) should return "1".

js
assert.strictEqual(sequence(1), "1");

sequence(27) should return "123456789101112131415161718192021222324252627".

js
assert.equal(sequence(27), "123456789101112131415161718192021222324252627");

--seed--

--seed-contents--

js
function sequence(n) {

  return n;
}

--solutions--

js
function sequence(n) {
  let result = "";
  for (let i = 1; i <= n; i++) {
    result += i;
  }
  return result;
}