Tell us what’s happening:
multiplesOf3and5(49); // returns 543
multiplesOf3and5(19564); // returns 89301183
These are the correct values, but the editor is telling me that my function isn’t returning any correct values. I tested my code in a nodejs interpreter via a GNU/Linux terminal.
multiplesOf3and5(1000); // returns 234168
I’m being told that my function doesn’t return a correct value on ANY number.
My function seems to work on all numbers except 1000.
Why does it work on all arguments except 1000? There must be a simple mistake I am making.
Your code so far
function multiplesOf3and5(number) {
// Good luck!
var count = 0;var nums = [];var sum = 0;
while (count < number) {
count += 1;
if (count % 3 == 0) {
nums.push(count);
}
else if (count % 5 == 0){
nums.push(count);
}
else {
; //do nothing
}
}
for (var i of nums) { sum += i;}; return sum;
}
multiplesOf3and5(1000);
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0.
Challenge: Problem 1: Multiples of 3 and 5
Link to the challenge:
https://www.freecodecamp.org/learn/coding-interview-prep/project-euler/problem-1-multiples-of-3-and-5