I can't write javascript or do programming all together
I learned the properties and syntax by watching courses and even built things alongside, but the thing is I can't do it on my own, My head is just getting empty when I open a .js file, just to build the damn thing I can watch others' code or ask a.i a little bit, but it doesn't seem like I am learning anything, nor I am developing any logic on my mind as a developer should, for example, to create an accordion the simple logic is if you click it it's going to open, Click again it's going to close, but How do I make it into reality, I don't know I just can't do it
71 Replies
practice and stop following and copying code
the more you build the more you can think about things and have references to fall back on
Like a accordion is pretty basic, start with that.
Honestly you can do most of it with just HTML too xD
i would actually step back a level
yea?
yes
whats simpler than an accordion?
sounds like op started by jumping head-first into programming
programming is like a cold swimming pool: first, you dip your toes, get in slowly and then swim
you just went head first to the deep end and struggle
if i asked you to write a simple counter, how would you do?
or something as basic as a function that divides a string and counts how many times each character was in it
could you do that?
It would take time, I think I can do that, Yeah, Much easier than that
taking this as an example, how would you write it?
Well, I can't tell write now from top of my head, but with error and trial I can figure this out
and that's why you struggle
instead of trial and error, how about you describe to me the steps you need to take to accomplish that task?
I can't
sorry, I understand now
i've had the same issue, i'd plan it out/use flowcharts which then made realise i had gaps in regards to syntax and how to actually apply them. knowing something and knowing how to apply it are different things
exactly
i think it was you who i gave some pointers about this
correct, i always start with planning now and then work from there, which made me aware that i know the steps but lack the syntax itself on how to make it work
Could you share how you managed to bridge those gaps in syntax and practical application?
he did it by doing what i asked you to do
Makes sense
i still cant, or rather yet, code from scratch but im getting there because i know what to do. i plan my stuff out and from there look up what i need
for example im creating a simple tip calculator to practice my skills, i plan it out and know that i need to display data
now its more about looking up some code or ways to do it rather than figuring out what needs to happen
One time I tried to write steps but then I was like "brain is not working, I have no idea" how am i gonna accomplish that simple stuff, and the temptation of looking up the answer is pretty bad
and that's how you never learn
but seriously, try breaking down the steps to do what i asked you
and you will see how much easier it is than if you try to find the answer
write the steps of a accordion down in a list of simple steps
wait, i asked him for something a lot simpler
an accordion is a bit more complicated than it seems
oh shit my bad, i didnt see that message
1: write the initial function take a argument (str)
2: return the lengths
what you think?
how do you calculate the lengths?
Well, If i just ask for the of strings length it's gonna return the numbers, right? so length = charectars
no
the problem is to count how many times all the characters of the string show in that string
which steps do you need to do to solve this?
No idea, I can't, It looks like i haven't learned anything
describe me how would you count how many times each character shows in the string
"cookies are good for you!"
I would start from the beginning and look at the string and from 1 and if a letter shows up again I will count them again like the character "o" it was 6 times
now, put that in a list
C = 1
O= 6
k = 1
i = 1
e = 2
s = 1
a = 1
r = 2
g = 1
d = 1
f = 1
y = 1
u = 1
no, the list of steps
like if you were solving a math problem
okay, something simpler
imagine im the dumbest person in the world
im thirsty and need to drink water
what should i do to drink water?
tell me, step by step, with details, what i have to do
If there is a bottle
1: take the bottle
2: open the cap
3: drink water
how do i take the bottle?
how do i open the cap?
how do i drink the water?
(yes, this is important)
you can assume that i know where the bottle is and i see it
1: to take the bottle, open your hands, go near it, grab it
2: to open the cap put your fingers around the cap, spin it Reverse clockwise
3. Now to drink the water, put the openning of the bottle in your mouth and now pour it into yours
now, combine both lists into one
Open your hands, approach the bottle, and grab it.
To open the cap, Wrap your fingers around the cap,
Turn the cap counterclockwise to unscrew it from the bottle.
Bring the bottle to your mouth.
Place the bottle opening near your lips. tilt the bottle to pour water into your now drink
does that sound good, I made it into one
almost
you have multiple steps into one line
each line should be a single step
for example, one line to opening the cap, one for approaching the bottle ...
okay okay
1: Approach the bottle
2: Open your hands
3: Now wrap your hands around the bottle
4: Grab it
5; Put your fingers around the cap
6: Rotate the cap counterclockwise to unscrew it
7: Place that bottles opening near your mouth
8: tilt that bottle
9: Now drink based on your needs
Was it good enough?
yes, it was
now, apply that exercise to counting characters
1: Count each character and remember it
2: whenever the same character comes up, Count it
3: and then after ending the string return all of the list counted charecter
How did do it?
now, can you be more specific?
but not too specific
you receive a string, but you're talking about counting each character
and remember how?
how do you check if the character exists?
for me personally, it's about learning how things function and the logic behind them rather than "how to create something". If i was looking at a website layout and two things were next to eachother, rather than saying "how do i put two things next to eachother" i would say "what do i know that aids in putting two things next to eachother", if you get that vibe? If you look at a lot of my posts where i ask for help in this channel, you'll see it's out of context questions, a lot of "what if" scenarios and me questioning how everything works, it might help you out if you look at it that way.
I would do if (str === true), if it returns false, then it means no string exist
well, put it in a list
everything goes to the list
the list is all the steps you have to do to solve your problem
also known as an "algorithm"
but again I know that from watching tutorials, so it kinda seems fake knowing that, idk maybe my approach to that is wrong
1: Check if the string exist or not
2: if it doesn't exist, return nothing
3: if it does exist, Count all of the characters and remember it
4: whenever the same character comes up, Count it again
5: at the end of the string return all of the list counted charecter
the string exists
you need to check characters
you see what's missing?
mmm, not yet
I wrote that in 3rd list, Didn't I?
If the string exists I need to check character
no
you're missing the step of getting the characters from the string
1: Check if the string exist or not
2: if it doesn't exist, return nothing
3: if it does exist Take each character from string
4: Count each of them
5: whenever the same character comes up, Count it again
6: at the end of the string return all of the list counted charecter
now, convert that exact list into code
Great job with the steps, really like that Epic. My input to this too -- and it might just be a me thing -- is it might be easier to separate them out into sublists, eg:
Might help to pair it with your code too, eg:
That way instead of having a list of 6 things to do you have a list of 3 for example with easy, manageable parts
the idea is to do the list before doing the code
because the code will translate directly into code
this is how i would do it:
- if the
str
parameter is empty
- stop processing
- divide the string into it's own characters
- for each character in str
- if the character is in the storage
- increment the character key in storage by 1
- otherwise
- create the character key in storage
- set the value to 1
- return the storagehow would you approach it if you know the list/steps but not the syntax itself, or the way to formulate the solution to look it up
if i have the list, i just have to follow it
each step can be a different search
if the person in question does not know the syntax or implementation for these steps:
- for each character in str
- if the character is in the storage
How would you solve it? or rather formulate the question in google etc if you arent familiar with the concepts
exactly that
"loop characters in string in zyx"
I am stuck here, I know the next syntax should be "loop" but I have no idea what to write
Makes sense,
How about if you don't know if you should write a loop or not? I mean there was also the same situation I ran into, Or you just keep searching relevant
"traverse characters in string in xyz"
or "go through characters in string in xyz"
or even "process individual characters from string in xyz"
there is no one search
You have a couple of the best programmers this server has to offer with b1 and Epic helping you so you're on good hands.
Just wanted to additionally suggest going through a course like this scrimba course that teaches you and has you code along right there in the browser to help make sure the concepts stick.
The new scrimba v2 is buggy though so I would stick with the stable version 1 (note the v1 in the url). A course like this will make sure you grasp the fundamentals and force you to put those concepts into action instead of the abstraction from watching YouTube tutorials where you think you understand until you sit down and make a brand new js file.
Scrimba
Learn JavaScript for free - 9-hour interactive tutorial
Learn the basics of JavaScript by solving 140+ interactive coding challenges. Along the way you will build a game, a browser extension, and even a mobile app!
Tip from a computer science teacher. Learn how to solve problems first. The programming languages are just tools to solve problems with.
that's basically what i tried to do, but im not perfect at it
@ἔρως
very good, but you have a bug: you're counting letters, not characters
and the string was
"cookies are good for you!"
you also don't need that if
to check if the string is empty
if it is empty, nothing will happen
it also isn't a good idea to use in
, but, it's perfectly fine for this example
alternativelly, you can use a map@ἔρως
Thanks for the tip, I really appreciate your help. I have a quick question if you don't mind. When you plan out the steps/logic before writing the code, what do you do if you feel stuck and can't pinpoint the problem area to figure out the steps? Given my situation, I am worried that I might get stuck even more before I start getting the hang of it. What would your advice be in that situation?
if im stuck, that means that the problem is too complex and must be split into parts, or there isn't enough information
What would your advice be in that situation?ask for targeted and specific help when that happens it's very much okay to need help, we all need help sometimes even as experts
that too
asking help is perfectly fine
i didn't learn to split a program at first sight
Got it, I will keep that in mind
Certainly
just remember that i don't do any miracles
i don't invent anything