Hello again guys. JS still frustrates me, bleh.
I'm trying to go through the Odin Project ( which I'm not really liking ..) and I'm trying to solve
https://projecteuler.net/problem=1 .
I feel really dumb, I have no idea what to do. Maybe I should learn a lot more before attempting this. I got my basic html down so far ( I have no idea how to put different JS sections on different parts of the page yet, ect, but we'll work on that.. )
I've been looking at other answers on github and I get the gist of it, but don't quite understand what people are saying.
Code:
var solution1 = function(x) {
var sum = 0;
for(var i = 1; i < x; i++) {
if(i % 3 === 0 || i % 5 === 0) {
sum += i;
}
}
console.log(sum);
};
solution1(1000)
So we have a variable called solution1, and we're having it become a function. Then we have a variable called sum, and it's equaled to 0. Moving on we have a for statement ( I haven't been able to understand much about loops yet, ) where variable i could equal 1, be less than x, or could have an increment on it. Then we have an if statement with %. I recently learned about this, where you divide x by y and then take the decimal and mulitple it by y again to get your answer?
Ex : 5 % 2 = 2.5
.5 * 2 = 1
So if i % 3 equals 0 or i % 5 equals 0, then the sum will be ??? I don't know how to understand the
line. Then we have a console statement saying the sum. I don't understand why we have
at the bottom either.
Sorry about the long post, like I've said, I've been reading other answers to this problem and nobody really explains what's happening? I don't even understand how people can think of this, it's so difficult. I don't want to be the annoying beginner in this thread, but I'm not sure where else I could post this, lol. Maybe I'll just go back and try to finish " Beginning JavaScript " .