Files
freecodecamp--freecodecamp/curriculum/challenges/english/blocks/daily-coding-challenges-javascript/681cb1b0dab50c87ddb2e51b.md
T
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

1.1 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
681cb1b0dab50c87ddb2e51b Challenge 10: 3 Strikes 28 challenge-10

--description--

Given an integer between 1 and 10,000, return a count of how many numbers from 1 up to that integer whose square contains at least one digit 3.

--hints--

squaresWithThree(1) should return 0.

assert.equal(squaresWithThree(1), 0);

squaresWithThree(10) should return 1.

assert.equal(squaresWithThree(10), 1);

squaresWithThree(100) should return 19.

assert.equal(squaresWithThree(100), 19);

squaresWithThree(1000) should return 326.

assert.equal(squaresWithThree(1000), 326);

squaresWithThree(10000) should return 4531.

assert.equal(squaresWithThree(10000), 4531);

--seed--

--seed-contents--

function squaresWithThree(n) {

  return n;
}

--solutions--

function squaresWithThree(n) {
  let count = 0;

  for (let i = 1; i <= n; i++) {
    const square = i * i;
    if (square.toString().includes('3')) {
      count++;
    }
  }

  return count;
}