- This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › Euler #1
http://codepen.io/gsg/pen/fLkyF
Problem:
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
I verified manually for <10 and <100 and in both cases the answer is right. What’s wrong with this code?
alert
.alert
function..
Beyond that, I’m not sure I follow your question. However, you say:
Find the sum of all the multiples of 3 or 5 below 1000.
but your code seems to find the sum of all natural numbers below 1000 multiplied by 3 where the product is below 1000, and multiplied by 5 where the product is below 1000. I don’t know if this is a problem with the way you’re writing the code, or the way you’re reading the question.
In either case, this sounds like a homework questionâ€¦? We’re not here to do homework for you. If there’s a specific question you’re asking, I’d be happy to help.
Sorry for the alert.
My question is why my code works correctly for multiples below 10, 100(I verified manually) but doesn’t work for 1000(the result is wrong).