Skip to main content
added 215 characters in body
Source Link

There's a few things you can do to improve this.

For your 'I have to guess up to which number the while loop have to go' problem, instead of going until you reach a specific number, you can tell it to go until you have an answer. You have your answer when i == 20, so if you initialize i outside the loop and you have it loop while(i !== 20), then it will just stop when you find the answer.

I'm not sure why you have separate variables for n and s. They seem to have the same function.

Another thing you can do is have your counter start at 20 (there's no way any number under 20 is divisible by all these numbers) and increase by 20 each iteration (skipping over all the numbers not divisible by 20 entirely).

edit: another answer that was posted while I was writing this says that you should increment your counter by 21. That is incorrect, 21 is not divisible by 20. I'd comment on that answer but I don't have the reputation to do that.

edit 2: another answer said it has to be over 210 (21 * 10) this is also incorrect because 20 is divisible by both. Maybe I'm misunderstanding the challenge here. If that's the case, somebody please let me know.

There's a few things you can do to improve this.

For your 'I have to guess up to which number the while loop have to go' problem, instead of going until you reach a specific number, you can tell it to go until you have an answer. You have your answer when i == 20, so if you initialize i outside the loop and you have it loop while(i !== 20), then it will just stop when you find the answer.

I'm not sure why you have separate variables for n and s. They seem to have the same function.

Another thing you can do is have your counter start at 20 (there's no way any number under 20 is divisible by all these numbers) and increase by 20 each iteration (skipping over all the numbers not divisible by 20 entirely).

edit: another answer that was posted while I was writing this says that you should increment your counter by 21. That is incorrect, 21 is not divisible by 20. I'd comment on that answer but I don't have the reputation to do that.

There's a few things you can do to improve this.

For your 'I have to guess up to which number the while loop have to go' problem, instead of going until you reach a specific number, you can tell it to go until you have an answer. You have your answer when i == 20, so if you initialize i outside the loop and you have it loop while(i !== 20), then it will just stop when you find the answer.

I'm not sure why you have separate variables for n and s. They seem to have the same function.

Another thing you can do is have your counter start at 20 (there's no way any number under 20 is divisible by all these numbers) and increase by 20 each iteration (skipping over all the numbers not divisible by 20 entirely).

edit: another answer that was posted while I was writing this says that you should increment your counter by 21. That is incorrect, 21 is not divisible by 20. I'd comment on that answer but I don't have the reputation to do that.

edit 2: another answer said it has to be over 210 (21 * 10) this is also incorrect because 20 is divisible by both. Maybe I'm misunderstanding the challenge here. If that's the case, somebody please let me know.

Source Link

There's a few things you can do to improve this.

For your 'I have to guess up to which number the while loop have to go' problem, instead of going until you reach a specific number, you can tell it to go until you have an answer. You have your answer when i == 20, so if you initialize i outside the loop and you have it loop while(i !== 20), then it will just stop when you find the answer.

I'm not sure why you have separate variables for n and s. They seem to have the same function.

Another thing you can do is have your counter start at 20 (there's no way any number under 20 is divisible by all these numbers) and increase by 20 each iteration (skipping over all the numbers not divisible by 20 entirely).

edit: another answer that was posted while I was writing this says that you should increment your counter by 21. That is incorrect, 21 is not divisible by 20. I'd comment on that answer but I don't have the reputation to do that.