Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

The Final Countdown

I got stumped on this algorithm. How would I begin to code this function?

This is based on “Flexible Countdown”. The parameter names are not as helpful, but the problem is essentially identical; don’t be thrown off! Given 4 parameters (param1,param2,param3,param4), print the multiples of param1, starting at param2 and extending to param3. One exception: if a multiple is equal to param4, then skip (don’t print) that one. Do this using a WHILE loop.

Example: Given (3,5,17,9), print 6,12,15 (which are all of the multiples of 3 between 5 and 17, except for the value 9).

Steven Parker
Steven Parker
230,248 Points

Please provide a link to the course page you are working with.

2 Answers

Steven Parker
Steven Parker
230,248 Points

You might start with your solution to the “Flexible Countdown”.

It says this problem is essentially identical to the “Flexible Countdown”. So you might start with the solution you wrote (or were shown) for that, and adjust the parameter names to fit.

Thanks buddy!

Jordany Rosas
PLUS
Jordany Rosas
Courses Plus Student 4,557 Points

You might want to start by writing out your plan of attack.

Set a var i = p2 since that's what you want to start at.

while i <= param3 (Where you want your while loop to stop)

if i != param4 and i % param1 == 0 (doesn't include param4 and is a multiple of param1) console.log(i)

Don't forget to increment your i.

Also, this doesn't include edge cases.