Yeah, I totally understand that feeling. It can really suck to feel frustrated and struggle and not feel like you are making progress. I have some problems at work that I’m really frustrated with right now and progress is painfully slow.
In this case, I would start with a skeleton of what you think the code might look like. You said a loop. Well, I’d start with that
function factoralize(num) {
for (let i = 0; i < num; i++) { // Loop bounds 0 to num I guess?
// Ok, I think I need a loop,
// but I don't know how to make this loop 'do' the magic
}
return magic; // Need to return something magical
}
It is totally ok to write some super broken code with comments. This is not much more than what your first instinct was, but we can help you fill stuff in.
In this case, you’d get a compile error, and would probably have this as a next step:
function factoralize(num) {
let magic = 1; // Need to declare the 'something magical' for the code to run
// Note: probably need a better variable name
for (let i = 0; i < num; i++) { // Loop bounds 0 to num I guess?
// Ok, I think I need a loop,
// but I don't know how to make this loop 'do' the magic
}
return magic; // Need to return something magical
}
With this we can start to talk about how that loop can make a factorial or if there is a different logical or control structure to consider.
If you want, we can use your version of something similar to build up to the solution.