Kindly fix this error issue | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Kindly fix this error issue

Greetings, I want to know that why my code is getting error and how can I solve it. Kindly let me know how can I do it. I'm a beginner and I want to know that https://code.sololearn.com/WV97K1792b9Q/?ref=app Thank you in advance! https://code.sololearn.com/WV97K1792b9Q/?ref=app

18th Jul 2022, 12:49 PM
Adarsh Addee
Adarsh Addee - avatar
11 Answers
+ 2
Functions exist for us to isolate some functionality from the rest of the code. This modularization keeps the code more organized and mantainable - you can fix or improve this functionality without worrying about the rest. They also allow you to use this functionality multiple times without repeating code. And, via parameters, you add flexibility, avoiding repeated code with small differences. With that in mind, I ask you: what's the difference of having all the code inside "demo" function, instead of in main (onload) function? Do the additional complexity helps in any way?
29th Jul 2022, 11:00 PM
Emerson Prado
Emerson Prado - avatar
+ 5
// You have to run the function: demo() // And change statement to: console.log(btn.value)
18th Jul 2022, 12:55 PM
JaScript
JaScript - avatar
+ 2
Adarsh Addee Because p is indeed not defined. What object did you expect to access?
19th Jul 2022, 4:35 AM
Emerson Prado
Emerson Prado - avatar
+ 1
Adarsh Addee I mean what object should be in p before writing in its innerText? In other words: you tried to put variable data in attribute in innerText of what?
20th Jul 2022, 6:06 PM
Emerson Prado
Emerson Prado - avatar
+ 1
Adarsh Addee It's more clear now, so I could read your code with its purpose in mind. I found 2 issues: 1. You created a function called "demo", with all your code and no parameters, and called it once, immediately. There's no need for this code section to be in a separated function - it goes better in the main function - onload. This is not critical, but it's important to avoid unecessary complexity. 2. The code gets the input tag value in the beginning, that is, before the user can write anything. When (s)he clicks the button, the code writes in data element this initial value. So just move your value query inside the event function.
26th Jul 2022, 1:19 AM
Emerson Prado
Emerson Prado - avatar
+ 1
This has 3 issues: 1. Everything we always say about having others fixing your code. 2. You're struggling with concepts. Seeing fixed code won't clear these concepts for you, so you will keep struggling every time. 3. I didn't see a sign of attempt to understand what I explained about these concepts. So I'll do what I think is best: walk you through the concepts and their application in your code. This way, you solve both the lack of understanding and the code in question. I'll divide in two parts: the "demo" function and the get value case.
29th Jul 2022, 10:52 PM
Emerson Prado
Emerson Prado - avatar
+ 1
Thank you for helping me☺️. I understand what's going on and now it's working properly 🎉. Thank you
30th Jul 2022, 12:27 AM
Adarsh Addee
Adarsh Addee - avatar
0
Please check why it's saying p is not defined
18th Jul 2022, 4:08 PM
Adarsh Addee
Adarsh Addee - avatar
0
I want to access the value of input. Whenever user enter any value I want that value. Kindly fix this!
20th Jul 2022, 11:19 AM
Adarsh Addee
Adarsh Addee - avatar
0
hello kindly help me I want to get the value of input tag in a variable and wants to show it in another tag p
24th Jul 2022, 3:23 PM
Adarsh Addee
Adarsh Addee - avatar
0
I can't understand it clearly 🙂. Can you please modify my code and correct it. I want to see the code so that I can see my mistakes 😊
29th Jul 2022, 1:46 PM
Adarsh Addee
Adarsh Addee - avatar