diff --git a/client/i18n/locales/english/intro.json b/client/i18n/locales/english/intro.json index 442d505e619..d3a0310f729 100644 --- a/client/i18n/locales/english/intro.json +++ b/client/i18n/locales/english/intro.json @@ -3522,6 +3522,12 @@ "In this lab, you will practice using higher order functions to find the symmetric difference between two arrays." ] }, + "lab-sum-all-primes-calculator": { + "title": "Build a Prime Number Sum Calculator", + "intro": [ + "In this lab you will build a sum all primes calculator that takes a number and returns the sum of all prime numbers that are less than or equal to that number." + ] + }, "review-javascript-higher-order-functions": { "title": "JavaScript Higher Order Functions Review", "intro": [ diff --git a/client/src/pages/learn/full-stack-developer/lab-sum-all-primes-calculator/index.md b/client/src/pages/learn/full-stack-developer/lab-sum-all-primes-calculator/index.md new file mode 100644 index 00000000000..bff32062cc2 --- /dev/null +++ b/client/src/pages/learn/full-stack-developer/lab-sum-all-primes-calculator/index.md @@ -0,0 +1,9 @@ +--- +title: Introduction to the Build a Sum All Primes Calculator +block: lab-sum-all-primes-calculator +superBlock: full-stack-developer +--- + +## Introduction to the Build a Sum All Primes Calculator + +In this lab you will build a sum all primes calculator that takes a number and returns the sum of all prime numbers that are less than or equal to that number. diff --git a/curriculum/challenges/english/blocks/lab-sum-all-primes-calculator/a3bfc1673c0526e06d3ac698.md b/curriculum/challenges/english/blocks/lab-sum-all-primes-calculator/a3bfc1673c0526e06d3ac698.md new file mode 100644 index 00000000000..f37e7aca10a --- /dev/null +++ b/curriculum/challenges/english/blocks/lab-sum-all-primes-calculator/a3bfc1673c0526e06d3ac698.md @@ -0,0 +1,89 @@ +--- +id: a3bfc1673c0526e06d3ac698 +title: Build a Sum All Primes Calculator +challengeType: 26 +dashedName: build-a-sum-all-primes-calculator +--- + +# --description-- + +In this lab, you will build a calculator that takes a number and returns the sum of all prime numbers that are less than or equal to that number. + +**Objective**: Fulfill the user stories below and get all the tests to pass to complete the lab. + +**User Stories:** + +1. You should have a `sumPrimes` function that accepts a number as an argument. +1. The `sumPrimes` function should return the sum of all prime numbers less than or equal to the provided number. +1. If the input number is less than `2`, the function should return `0`. + +# --hints-- + +You should have a `sumPrimes` function. + +```js +assert.isFunction(sumPrimes); +``` + +`sumPrimes(10)` should return `17`. + +```js +assert.strictEqual(sumPrimes(10), 17); +``` + +`sumPrimes(5)` should return `10`. + +```js +assert.strictEqual(sumPrimes(5), 10); +``` + +`sumPrimes(2)` should return `2`. + +```js +assert.strictEqual(sumPrimes(2), 2); +``` + +`sumPrimes(0)` should return `0`. + +```js +assert.strictEqual(sumPrimes(0), 0); +``` + +`sumPrimes(977)` should return `73156`. + +```js +assert.strictEqual(sumPrimes(977), 73156); +``` + +# --seed-- + +## --seed-contents-- + +```js + +``` + +# --solutions-- + +```js +function sumPrimes(num) { + function isPrime(n) { + if (n < 2) return false; + for (let i = 2; i <= Math.sqrt(n); i++) { + if (n % i === 0) { + return false; + } + } + return true; + } + + let sum = 0; + + for (let i = 2; i <= num; i++) { + if (isPrime(i)) { + sum += i; + } + } + return sum; +} +``` diff --git a/curriculum/structure/blocks/lab-sum-all-primes-calculator.json b/curriculum/structure/blocks/lab-sum-all-primes-calculator.json new file mode 100644 index 00000000000..9fc27a1e6f0 --- /dev/null +++ b/curriculum/structure/blocks/lab-sum-all-primes-calculator.json @@ -0,0 +1,15 @@ +{ + "name": "Build a Sum All Primes Calculator", + "isUpcomingChange": false, + "dashedName": "lab-sum-all-primes-calculator", + "helpCategory": "JavaScript", + "blockLayout": "link", + "blockType": "lab", + "usesMultifileEditor": true, + "challengeOrder": [ + { + "id": "a3bfc1673c0526e06d3ac698", + "title": "Build a Sum All Primes Calculator" + } + ] +} diff --git a/curriculum/structure/superblocks/full-stack-developer.json b/curriculum/structure/superblocks/full-stack-developer.json index f7468872935..74ffab7b5f7 100644 --- a/curriculum/structure/superblocks/full-stack-developer.json +++ b/curriculum/structure/superblocks/full-stack-developer.json @@ -401,6 +401,7 @@ "lab-book-organizer", "lab-sorted-index-finder", "lab-symmetric-difference", + "lab-sum-all-primes-calculator", "review-javascript-higher-order-functions", "quiz-javascript-higher-order-functions" ]