Skip to content
Advertisement

Why is my function returning full list instead of just a total count?

I’ve been working on a problem for a class that involves random number generation and returning a count for those divisible by 7 or 13. The function appears to work, or is at least returning the proper values along the steps. But, it returns a list for the count instead of a single value. What am I doing wrong? The requirements and my code so far are:

Develop and call a function that will:

  1. Generate a random number n with a value between 1 and 1,000.
  2. In the range of (n, n+200), iterate each number and count how many of them are divisible by 7 and how many of them are divisible by 13.
  3. Print out the result
JavaScript

Advertisement

Answer

You are printing the total in each iteration. You should print it after for loop.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement