Must finish in one hour divisible by 10 (javascript)

this is my code so far, and I do not know how to finish it or what I am doing wrong.

function num(){
def divisible_by_ten(nums):
  count = 0
  for num in nums:
    if num % 10 == 0:
      count+=1
    return count
#Uncomment the line below when your function is done
print(divisible_by_ten([20, 25, 30, 35, 40]))
}

CodeAcademy says:

  • Please do not post the answer without an explanation. Code only answers will be removed. Help the user learn to troubleshoot.

Hi!,
First, What are you programming language using?

function num(){ …blablabla }

It is Javascript (Not Python)

def divisible_by_ten(nums):
…blablabla

It is Python (Not Javascript)

The JavaScript language does not mix with Python, just as the Portuguese language does not mix with French.
First, You must define which programming language to use to solve the exercise.

function to count how many of the numbers in the array (or list) are divisible by 10
JavaScript:

function divisibleBy10(nums) {
  let count = 0;
  for (let num of nums) {
    if (num % 10 == 0) {
      count += 1;
    }
  }
  return count;
}
console.log(divisibleBy10([20, 25, 30, 35, 40]));

Python:

def divisible_by_ten(nums):
  count = 0
  for num in nums:
    if num % 10 == 0:
      count += 1
  return count

print(divisible_by_ten([20, 25, 30, 35, 40]))

In either case, notice that the return count is outside of the for loop.
In Python, this is done with the indentation (the amount that line is indented should match the indention of the other stuff outside the loop).
In JavaScript, the { or } is used to accomplish that.

Five minute JS

function divisibleByTen (array) {
    return array.filter(x => ! (x % 10)).length
}

 > divisibleByTen([20, 25, 30, 35, 40])
<- 3
 > 

Five minute Python

def divisible_by_ten(lst):
    return len([x for x in lst if not (x % 10)])

>>> divisible_by_ten([20, 25, 30, 35, 40])
3
>>> 
1 Like

We’ve got a few minutes left to make a function that will test the divisibility of any number by any number, and do it on the fly, if needs be. A factory would fit that bill. We don’t need to code a whole stack of functions, just one prototype to enclose our constant in a produced function.

JS

const divisible = function (k) {
    return u => u.filter(x => ! (x % k)).length
}

 > const mod5 = divisible(5)
 > mod5([4, 5, 13, 19, 25, 29, 31, 35, 40, 44])
<- 4

Python, as well, to be fair…

def divisible(k):
    return lambda u: len([x for x in u if not (x % k)])

>>> mod5 = divisible(5)
>>> mod5([4, 5, 13, 19, 25, 29, 31, 35, 40, 44])
4
>>> 

On the fly…

>>> divisible(4)([4, 5, 13, 19, 25, 29, 31, 35, 40, 44])
3
>>> 
1 Like