Hello my teacher, @chrisdavidmills I don’t know, what is problem at my code?
Hi there @Bumidu_yasith!
I tried out your code in my example, and it worked fine.
If you are getting the error “Cannot read property ‘addEventListener’ of null”, then it must relate to this line:
randomize.addEventListener('click', result);
It is saying that randomize
has a value of null
, which means it isn’t being set properly. We are setting the value of randomize
in this line:
const randomize = document.querySelector('.randomize');
which should select and store a reference to the following button inside the HTML:
<button class="randomize">Generate random story</button>
does your random story button have class="randomize"
included on it?
Hi there @krasnovdanial, hope you are well.
This is a pretty easy fix. When you run your app and open the devtools, the JS console gives an error of “Loading failed for the with source “https://chartreuse-monkey.glitch.me/JS/script.js””, which indicates that you are simply pointing at the wrong location for the script.
Removing JS/
will cause the script to load correctly.
After that you’ve got a couple of errors in your JS to fix, and it should work. Again, look at the error messages in the DevTools JS console to help you.