+ 4
Where is my mistake???
please help me https://code.sololearn.com/W9q6V9rt1T5e/?ref=app
5 odpowiedzi
+ 3
i added something check line 7
https://code.sololearn.com/WsXTL4VZ672O/?ref=app
+ 2
When the script loads the HTMl content is not loaded yet so it returns undefined or null you can use window.setTimeout(function,Time in milliseconds) or put a script at the end of the document calling a function on the main script to start the whole script.
hope it helped.I tried to fix it, link:https://code.sololearn.com/WgQS6CHCCihW/#js
+ 2
do you want to sort by name or year after clicking on the button?
+ 2
yes @nomeh
+ 1
All you need to do its wrap the first call to displayCars in a window.onload function as @neicore has done or you can use something like the jQuery document.ready function. The problem is that displayCars() is being called prior to the body of the html being built and added to the DOM. SL injects the JS from the JS tab into the head of the html so it is run first. Of course, you won't notice that it is actually working correctly (except the errors will be gone) until you change the order of your cars variable as they are already sorted in the order that the sort method would sort them.