Please why is the word "happy" not appended to the list | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Please why is the word "happy" not appended to the list

https://code.sololearn.com/Wugiea6DVeK7/?ref=app

23rd Feb 2018, 3:27 AM
Sammy
Sammy - avatar
7 Answers
+ 5
I don't know if you changed things or not, but happy isn't added to the list as line 8 generates a runtine error. 'getElementsByTagName' returns a list as indicated by the 's' of 'Elements'. Trying to use the list as a single element fails. Change 'total.appendChild' to 'total[0].appendChild' to reference the one and only 'ul' tag and happy will be added to the list. However, you HTML will look like this: <ul> <li>rat</li> <li>goat</li> <li>woman</li> <li><text>happy</text></li> </ul>
23rd Feb 2018, 3:49 AM
John Wells
John Wells - avatar
+ 2
I added it Sir but it still isn't appending and returning the runtime error
23rd Feb 2018, 4:49 AM
Sammy
Sammy - avatar
+ 2
Sorry for the delay. Here you go: https://code.sololearn.com/WH7eLK6MG9a4
23rd Feb 2018, 5:25 PM
John Wells
John Wells - avatar
+ 1
please could you please fork it and paste the link
23rd Feb 2018, 4:50 AM
Sammy
Sammy - avatar
+ 1
and please what do you mean by 's" of elements
23rd Feb 2018, 5:08 AM
Sammy
Sammy - avatar
+ 1
thanks alot sir
23rd Feb 2018, 6:04 PM
Sammy
Sammy - avatar
0
As @John wells said, replace total with total[0] and your statement will look like this: total[0].appendChild(add);
23rd Feb 2018, 11:33 AM
Vikash Pal
Vikash Pal - avatar