Exercise 2: Fix the Code

Learn how to debug the code.

Problem statement

The code given in this exercise will not terminate. You have to fix the code to get the desired output.

📍 Use your knowledge from the previous lessons to debug the code.

Function description

The sumOfPrimes() function sums all the prime numbers up to the age given as a parameter. The age itself is also included in the sum if it is a prime number.

To check whether a number is prime or not, sumOfPrimes() calls the isPrime() function, which returns true if a number is a prime number. Otherwise, it returns false.

📝Note: One is not a prime number.

Sample input and output

Input Output
10 17
15 41
20 77

Let’s get started! You need to fix all the errors to make this code work.

You can run the ESLint on the code to see the list of errors, as we have done in the code widget below.

Get hands-on with 1400+ tech skills courses.