Function Problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Function Problem

Hey guys... Why myFunction doesn't work here and doesn't print the comments? Please help! I want this code to print the comments and also create button number 2 after adding five comments. Help me if you know how to do it https://code.sololearn.com/WAM8w5gWtOsa/?ref=app

22nd Aug 2020, 9:23 AM
Shaghayegh
Shaghayegh - avatar
14 Answers
0
In button tag you mised () myfunction()
22nd Aug 2020, 9:27 AM
Divya Mohan
Divya Mohan - avatar
0
Line 41 and 64 document dudument line 43 getElementsByTagName missed s and document
22nd Aug 2020, 9:28 AM
Divya Mohan
Divya Mohan - avatar
0
Divya Mohan i corrected them😁 but it still dosen't print the comments... it just prints [object inputHTMLElement]
22nd Aug 2020, 9:38 AM
Shaghayegh
Shaghayegh - avatar
0
Line 63 Correct it as document.getElementsByTagName
22nd Aug 2020, 9:40 AM
Divya Mohan
Divya Mohan - avatar
0
Line 43 document.getElementById("cmnt").value You missed value there
22nd Aug 2020, 9:43 AM
Divya Mohan
Divya Mohan - avatar
0
Divya Mohan ok😁🤦‍♀️ after adding 5 comments it gives me error instead of making a button
22nd Aug 2020, 10:06 AM
Shaghayegh
Shaghayegh - avatar
0
Is it working well as expected ??
22nd Aug 2020, 10:08 AM
Divya Mohan
Divya Mohan - avatar
0
Divya Mohan yes i corrected and it works. but the button will not be created after adding more than 5 comments
22nd Aug 2020, 10:10 AM
Shaghayegh
Shaghayegh - avatar
0
Still you have an error in line 63 You have missed document while accessing body element
22nd Aug 2020, 10:31 AM
Divya Mohan
Divya Mohan - avatar
0
It will be better if your change type from submit to button in line 33. I get everything working fine then.
22nd Aug 2020, 10:34 AM
Divya Mohan
Divya Mohan - avatar
0
Divya Mohan thanks. but just how to say just stop after adding button 2. and if pressed submit again dont make a new button 2 again?
22nd Aug 2020, 10:51 AM
Shaghayegh
Shaghayegh - avatar
0
In line 59 You have write else Replace it with else if(x == 6 ) ______&_____________ In this way you can also make an algorithm that if x%6 ==0 (means if x is divisible by 6 ) then create a button else type cmnt
22nd Aug 2020, 10:59 AM
Divya Mohan
Divya Mohan - avatar
0
Divya Mohan thank you, i have another question, how can i put the button 2 beside the button 1 in this code? one of them is in html and one of them is in script, and they don't come exactly after each other.
23rd Aug 2020, 7:30 AM
Shaghayegh
Shaghayegh - avatar
0
You can use insertAdjacentElement property of js Ex- Target button 1 as btn1 And button 2 as btn2 Then btn1.insertAdjacentElement("afterend","btn2"); It will place btn2 just after btn1 hope it will work share code with error if not.
23rd Aug 2020, 7:38 AM
Divya Mohan
Divya Mohan - avatar