Should I be worried?

Tell us what’s happening:
Describe your issue in detail here.

So I’m starting to get worried that I’m not learning things as I should because a lot of the time, the solutions that I come up with (though they work) look very different from the solutions that are provided. They’re a lot longer and messier. This problem in particular is a prime example. If I try to think of solutions on my own without cheating, I end up writing janky code so I just want to ask if it’s alright to keep going this way or if it’s better to just look at the proper solution and study that instead?

  **Your code so far**

function sumAll(arr) {
  let emptyArr = []
  if (arr[0] < arr[1]) {
for (let i = arr[0]; i <= arr[1]; i++) {
emptyArr.push(i);
}
  } else if (arr[0] > arr[1]) {
     for (let i = arr[0]; i >= arr[1]; i--) {
emptyArr.push(i);
  } 
  }
let newArr = emptyArr.reduce((a, b) => a + b, 0)
return newArr;
}

sumAll([1, 4]);


  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36 Edg/100.0.1185.44

Challenge: Sum All Numbers in a Range

Link to the challenge:

Hi @CYusi !

Welcome to the forum!

The solutions provided are just one way to solve the problem.
All of the solutions have been provided by the community.
Sometimes there are better solutions then provided in the fcc guide.

The goal is to work on your problem solving skills and solve it on your own which is what you are doing.
Don’t worry about trying to come up with the best solution.

As long as you understand the problem, then that is what matters.

Over time, you will be able to better optimize your solutions.

But for now, just focus on learning and progressing.

hope that helps!

Yes that helps a ton. Thank you!

If it works then it is a proper solution.

Most of the challenges can be completed in various ways, to determine which one is best some additional, specific criteria are needed. Without that only one thing can be said for sure - they all are solving the challenge.

Keep also in mind, the point at which code is working and doing what it should, is great moment to consider what could be improved, what changed, etc. That’s normal.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.