I am trying to learn JavaScript from here . As told here I have following main.js file which will change the background color but nothing is happening when I click the button :-
var btn = document.querySelector('button');
function bgChange() {
var rndCol = 'rgb(' + random(255) + ',' + random(255) + ',' + random(255) + ')';
document.body.style.backgroundColor = rndCol;
}
btn.onclick = bgChange;
and index.html file:-
<!DOCTYPE html>
<html>
<head>
<title>Js</title>
<link rel="stylesheet" href="stylesheet.css" />
<script src="main.js"></script>
</head>
<body>
<button>Dont click</button>
<p id="p1" > om !!!!</p>
</body>
</html>
When I open this firefox and click on the button nothing happens please help me :(