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
b1mind
b1mind7d ago
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
ἔρως
ἔρως7d ago
i would actually step back a level
b1mind
b1mind7d ago
yea?
ἔρως
ἔρως7d ago
yes
b1mind
b1mind7d ago
whats simpler than an accordion?
ἔρως
ἔρως7d ago
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?
Abdur Rahman
Abdur Rahman7d ago
It would take time, I think I can do that, Yeah, Much easier than that
ἔρως
ἔρως7d ago
taking this as an example, how would you write it?
Abdur Rahman
Abdur Rahman7d ago
Well, I can't tell write now from top of my head, but with error and trial I can figure this out
ἔρως
ἔρως7d ago
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?
Abdur Rahman
Abdur Rahman7d ago
I can't sorry, I understand now
rayannn
rayannn7d ago
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
ἔρως
ἔρως7d ago
exactly i think it was you who i gave some pointers about this
rayannn
rayannn7d ago
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
Abdur Rahman
Abdur Rahman7d ago
Could you share how you managed to bridge those gaps in syntax and practical application?
ἔρως
ἔρως7d ago
he did it by doing what i asked you to do
Abdur Rahman
Abdur Rahman7d ago
Makes sense
rayannn
rayannn7d ago
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
Abdur Rahman
Abdur Rahman7d ago
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
ἔρως
ἔρως7d ago
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
rayannn
rayannn7d ago
write the steps of a accordion down in a list of simple steps
ἔρως
ἔρως7d ago
wait, i asked him for something a lot simpler an accordion is a bit more complicated than it seems
rayannn
rayannn7d ago
oh shit my bad, i didnt see that message
Abdur Rahman
Abdur Rahman7d ago
1: write the initial function take a argument (str) 2: return the lengths what you think?
ἔρως
ἔρως7d ago
how do you calculate the lengths?
Abdur Rahman
Abdur Rahman7d ago
Well, If i just ask for the of strings length it's gonna return the numbers, right? so length = charectars
ἔρως
ἔρως7d ago
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?
Abdur Rahman
Abdur Rahman7d ago
No idea, I can't, It looks like i haven't learned anything
ἔρως
ἔρως7d ago
describe me how would you count how many times each character shows in the string "cookies are good for you!"
Abdur Rahman
Abdur Rahman7d ago
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
ἔρως
ἔρως7d ago
now, put that in a list
Abdur Rahman
Abdur Rahman7d ago
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
ἔρως
ἔρως7d ago
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
Abdur Rahman
Abdur Rahman7d ago
If there is a bottle 1: take the bottle 2: open the cap 3: drink water
ἔρως
ἔρως7d ago
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
Abdur Rahman
Abdur Rahman7d ago
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
ἔρως
ἔρως7d ago
now, combine both lists into one
Abdur Rahman
Abdur Rahman7d ago
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
ἔρως
ἔρως7d ago
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 ...
Abdur Rahman
Abdur Rahman7d ago
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?
ἔρως
ἔρως7d ago
yes, it was now, apply that exercise to counting characters
Abdur Rahman
Abdur Rahman7d ago
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?
ἔρως
ἔρως7d ago
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?
snxxwyy
snxxwyy7d ago
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.
Abdur Rahman
Abdur Rahman7d ago
I would do if (str === true), if it returns false, then it means no string exist
ἔρως
ἔρως7d ago
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"
Abdur Rahman
Abdur Rahman7d ago
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
ἔρως
ἔρως7d ago
the string exists you need to check characters you see what's missing?
Abdur Rahman
Abdur Rahman7d ago
mmm, not yet I wrote that in 3rd list, Didn't I? If the string exists I need to check character
ἔρως
ἔρως7d ago
no you're missing the step of getting the characters from the string
Abdur Rahman
Abdur Rahman7d ago
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
ἔρως
ἔρως7d ago
now, convert that exact list into code
vince
vince7d ago
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:
1. check if string exists
1a. if string is null, return null
1b. if string isn't null, parse string
2. ...
1. check if string exists
1a. if string is null, return null
1b. if string isn't null, parse string
2. ...
Might help to pair it with your code too, eg:
const string = '123456';

// 1 - check if string exists
if (string == null) { // 1a - if string is null
return null;
} else { // 1b - if string isn't null
...
}
const string = '123456';

// 1 - check if string exists
if (string == null) { // 1a - if string is null
return null;
} else { // 1b - if string isn't null
...
}
That way instead of having a list of 6 things to do you have a list of 3 for example with easy, manageable parts
ἔρως
ἔρως7d ago
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 storage
rayannn
rayannn7d ago
how 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
ἔρως
ἔρως7d ago
if i have the list, i just have to follow it each step can be a different search
rayannn
rayannn7d ago
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
ἔρως
ἔρως7d ago
exactly that "loop characters in string in zyx"
Abdur Rahman
Abdur Rahman7d ago
const string = "Cookies are good for you"
const stringCounter = (str)=>{
let count={};
if(str){

}
return count;
}
const string = "Cookies are good for you"
const stringCounter = (str)=>{
let count={};
if(str){

}
return count;
}
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
ἔρως
ἔρως7d ago
"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
clevermissfox
clevermissfox7d ago
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!
ultrawyrm
ultrawyrm7d ago
Tip from a computer science teacher. Learn how to solve problems first. The programming languages are just tools to solve problems with.
ἔρως
ἔρως7d ago
that's basically what i tried to do, but im not perfect at it
Abdur Rahman
Abdur Rahman7d ago
@ἔρως
const string = "cookies are good for you";

const StringCounter = (str) => {
let counter = {};
const strWithoutSpaces = str.replace(/\s/g, "");
if (!strWithoutSpaces) {
return {};
}
for (let char of strWithoutSpaces) {
if (char in counter) {
counter[char]++;
} else {
counter[char] = 1;
}
}
return counter;
};

console.log(StringCounter(string));
const string = "cookies are good for you";

const StringCounter = (str) => {
let counter = {};
const strWithoutSpaces = str.replace(/\s/g, "");
if (!strWithoutSpaces) {
return {};
}
for (let char of strWithoutSpaces) {
if (char in counter) {
counter[char]++;
} else {
counter[char] = 1;
}
}
return counter;
};

console.log(StringCounter(string));
ἔρως
ἔρως7d ago
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
Abdur Rahman
Abdur Rahman7d ago
@ἔρως 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?
ἔρως
ἔρως7d ago
if im stuck, that means that the problem is too complex and must be split into parts, or there isn't enough information
Jochem
Jochem7d ago
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
ἔρως
ἔρως7d ago
that too asking help is perfectly fine i didn't learn to split a program at first sight
Abdur Rahman
Abdur Rahman7d ago
Got it, I will keep that in mind Certainly
ἔρως
ἔρως6d ago
just remember that i don't do any miracles i don't invent anything