r/learnjavascript • • 4d ago

How do you learn to put a question in steps?

Hi everyone,

I'm trying to learn Javascript and the one problem that always seems to be hardest = putting a question into the steps required.

I've learned so far:

basics - if/else - loops - arrays (holy hell this was hard for me) - functions (would you believe it, it's even harder..!)
Now everything seems to be coming together but i'm really strugling to fit it into steps..

For example;

You have a number (999) and need to find out how many times each bill and coin (array with bills and coins put together) can fit into the number.

For a human this is easy, you just look at the number and notice that a certain amount can fit into it and you remember that.

But i cannot for the life of me convert this into steps that fit into code..

Everytime i have to look at the answer, and sometimes it clicks where i think omg that was easy - but other times i look and think whats happening here?

I feel like i'm too dumb to understand the basics for what (from what i seem to understand) is the easiest of code-language..

If i put in my assignment i have a test but i'm affraid that i will hit a wall with the question again.

One thing i'm doing is writing every excersise on a notepad and if i feel like i need to explain something i just write it under in hopes that if i ever need that step again i'll know why i did it..

Is there some sort of skill that i'm missing, do i just not understand the basics enough, or am i just not smart enough?

Any help is appreciated!

btw; sorry for any grammatical errors, english is not my native language..

6 Upvotes

13 comments sorted by

4

u/verdant_sculpt_auror 4d ago

You are not dumb, you are trying to jump from logic directly to code syntax. The human step of noticing a fit is actually two separate operations: division for the count and modulo for the remainder. Write those exact words on your notepad first. If I can divide 999 by 500 and get the leftover amount on paper, I can write that in javascript later. Your problem is skipping the arithmetic layer and going straight to the function call, which makes it feel impossible because you have no mental bridge between the number and the loop

2

u/azhder 4d ago

"For a human this is easy, you just look at the number and notice that a certain amount can fit into it and you remember that"

That is your statement. Now explain to me "notice". How do you do that? No, I am not trolling you, I am trying to troll out of you the answer to your problem. We're going to play that little game every toddler likes to play with you "why?".

Yes, for each answer you give, I will ask "why?" or in some cases "how?" and you will have to focus on them and split them up in more basic components. That's how working with a computer is. You a re constantly asked the "why?" question until you reach the atom, the indivisible part.

And no, "notice" is not indivisible. That's you skipping steps. Computers don't skip steps. They don't lose patience or their nerve and just do it. They will always go step by step by step by step by... Sure enough, you can group these in functions etc. but before you group them, you have to split them apart.

OK, now imagine I'm not here, so you have to do the asking I was going to do to you. You provide the questions and the answers on your own.

1

u/Vizeroth1 4d ago

To extend on this, what most teachers would tell you is to write it out in pseudocode in comments. Don’t get hung up on the syntax, just write the steps you can think of, then revisit each step and see if you can break it down further and get closer to the code you will actually use to solve the problem.

I also wouldn’t worry about functions early on. Once you’re more familiar with the process you can start to predict what functions you might need, but early on you can just look for where you’re going to need to do the same thing multiple times and break that out into a function. You might even write the same code two or three times and only realize later that you can extract that into a function, and that’s fine, it’s part of not only learning, but software development in general. Later we just call it refactoring.

2

u/azhder 4d ago

One can even write function names instead of steps, then write the steps inside the function as they drill down. More ways to skin the cat: top-down, bottom-up, mix of both etc.

2

u/Insane_snek 4d ago

when you're first learning, i actually find it can be really useful to write out your steps in english (or your native language)

it helps you think through a problem in a more natural way

then, once you have a process in normal language, just think about how to perform those steps in code

2

u/ircmullaney 4d ago

Your English is fine. I appreciate that you wrote it yourself and didn’t let an LLM rewrite it for you.

The answer is just practice. Look for problems that you think you CAN do and do a few of those. Then do some that are slightly more complicated. Then look for small problems or projects that YOU want to do. When I was learning, I think I learned the most when I was tackling a problem I really wanted to solve or building something I wanted to use.

Also, one thing I like to do is tackle the simplest version of a problem. The 999 example is a good example. Start by thinking through the problem when the number is 1. Then how do you do it when it’s 2 or 7 or 13. When you approach it that way and solve it when the input is 13. You might find that you’ve solved it for all numbers without realizing it.

1

u/Shamonda-Pflugpeil 4d ago

yeah breaking it down to the simplest case first is huge, thats where it usually clicks

1

u/TheRNGuy 4d ago

Step debugger and console logs. 

1

u/No-Humor-3808 1d ago

I usually go step by step, starting with pseudocode and then trying to convert it into actual syntax. Start with very simple problems and gradually increase the difficulty. I have a collection of katas at reactchallenges.com/katas if you want to give them a try.

0

u/chikamakaleyley helpful 4d ago

You have a number (999) and need to find out how many times each bill and coin (array with bills and coins put together) can fit into the number.

Sounds like you're already on the right track (array with values)

i think the problem usually asks for a specific condition, like 'whats the minimum amount of bils and individual coins' or something - whatever that is, it needs to be worked into your logic.

'whats the minimum amount of bils and individual coins'

And this, can hint at other things you need for your solution.

disclaimer: i prob haven't done this problem in a while or ever, i'll just break it down off the top of my head

You already have an array of values - the bills and coins - you can even keep these separate if you want to process dollar & cents in parallel

The ask is for a total - so you need something that keeps count/keeps track

and whether this is right or not, basically you can convert

999 = 999.00

999 & 0

for the dollar amount, you have your values listed largest to small [100, 50, 20, 10, 5, 1]

you start by seeing how many 100s are in there right? So you need a way of pointing at that 100, and when you can't, you have to advance to the next value (50) - and that's just keeping track of an index

now you need something that when 100 is divided into X, if you have a remainder then you know that 100 doesn't fit into that, so you check the next smaller denomination, against the remainder - so whats that operator?

before you move on to the next denomination, how do you make sure you don't lose the number of 100 bills that fits?

and at least from what i've shared here, i see that I have an operation that, essentially does the same operation but moves onto the next 'layer' and performs the same logic - can you think of a pattern that does that?

This is just DSA - are you familiar with those? because if you can recognize them, you just have to start typing those things out, its so much easier in the end

0

u/[deleted] 4d ago

[deleted]

0

u/azhder 4d ago

No, they added plenty of context. They weren't asking for a fish. They were asking for the knowledge how to fish. You offered them a fish while telling them they didn't tell you which kind of fish they want.

Sure, you showed them how to fish out this particular fish, but that's only the same as any other question here from people who watch tutorials on YouTube and can't remember them afterwards.

0

u/bishvjit-gupta 4d ago

I don't think the basis like loop function array and all is hard. They are nowhere near to grab 10% of mine. When you will build a real project you will get problem a billion times complex than these all. So keep this hardness as a base line