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]))
}
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.
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.