# Basic Algorithm Scripting - Truncate a String

pls i need help on Basic Algorithm Scripting challenge.

am finding it difficult to solve the challenges
and when i check the hints and solutions i also find it hard it to understand the solutions.

i was only able to solve the :

1. convert Celsius to Fahrenheit
2. reverse a string and
3. factorialize a number
all by my self (without copy/paste solutions) .

And now i think i need to start all over again to understand all the concept so that i can be capable to solve the “Basic Algorithm Scripting” challenges on my own.

I need advice on what challenge to start all over with, so that i can get the understanding to solve all challenges in “Basic Algorithm Scripting”

``````function truncateString(str, num) {
return str;
}

``````

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

Challenge: Basic Algorithm Scripting - Truncate a String

Hello
I had the same problems when I started to do all. Do not think that you have to solve the problems all alone. It takes time to understand them.
On youtube you can find guys, who are solving those problems and explaining them as well. If you search for the title of the task on youtube, you can get really good help from usefulprogrammer. He solved all the algorithms and explaind them as well. After understanding all, or you can do it one by one try to sort out the problem by yourself again and again.
Typing code is a really good practice.

1 Like

I would try to avoid solutions or walkthroughs. Understanding someone else’s code is an important skill but a different skill than writing solutions. I would ask here about what parts of the challenge you don’t understand.

1 Like

i am finding it difficult to use the FOR LOOP (the statement part of the for loop ) correctly on some " Basic Algorithm Scripting" challenges.
I also have issues with recursion too.

But the real issue is that i find it hard to apply the knowledge in the right way, .
that’s why i need advice on what to do.
(to start all over again OR to pick some completed challenge to start with)

Hi @Boazoft !

Most beginners struggle to solve the algorithm challenges because it is a different type of thinking. It is important to remember that you are new to this kind of problem solving and that it will take a while before you start to understand how to approach these types of problem. You will have to give it time and practice.

I don’t think you need to start all over again.
I just don’t think you have a plan for how to approach these problems.

Here is what I would suggest.

1. First solve the problem away from code. Meaning, how would you solve the problem as a human with just pen and paper and pseudocode.
2. write down the steps you took to solve the problem
3. then slowly take each step and tun it into code
4. when you get stuck, research docs, the forum and reach out to ask questions when you get stuck

This will get better over time with continually practice.

Most people struggle with recursion.
Good news is that you won’t be using recursion every single day on the job.

While it is helpful to know and there will be times where a recursive solution makes sense, don’t worry if it doesn’t make 100% sense right now.
Continue to read articles and watch videos on recursion.
Keeping practicing different algorithm challenges and the more problems you solve the better you will start to understand recursion.

My advice is to reach out more to the forum when you get stuck.

Also, practicing with other sites like exercism or codewars will help you practice your problem solving skills.

When I first started learning back in 2020, I struggled with the algorithm sections because I didn’t know how to problem solve and was new to programming. But I kept taking it day by day and eventually starting to enjoy those challenges.

Hope that helps

2 Likes

the correct code is:

Mod Edit: SOLUTION REMOVED

To start the code, we need to use either a for loop or an if loop because we have two variables, str and num. Since for is not useful in this case, we need to use an if loop, saying that str is > a num (I’m writing a condition) then, return str.slice(0, num) + “…”; this is the condition to make it work properly. else return str, this is the second condition I set to return, but it could also be written else return “come back”

1 Like

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

thanks for the advice @ jwilkins.oboe.
i would try to apply those suggested step you gave

@richard95 thanks for the walkthrough solutions.

Ah sorry, now that you say so I won’t do it again

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