The Javascript code is embedded in the HTML but want to do a link externally to the JS script instead of having it inside the HTML but I would end up with some global or local variable problems where a function is ran before it is defined
any help with this problem?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<title>JavaScript label example</title>
<style>
p {
font-family: 'helvetica neue', helvetica, sans-serif;
letter-spacing: 1px;
text-transform: uppercase;
text-align: center;
border: 2px solid rgba(0,0,200,0.6);
background: rgba(0,0,200,0.3);
color: rgba(0,0,200,0.6);
box-shadow: 1px 1px 2px rgba(0,0,200,0.4);
border-radius: 10px;
padding: 3px 10px;
display: inline-block;
cursor: pointer;
}
</style>
</head>
<body>
<p>Player 1: Chris</p>
</body>
<script>
var para = document.querySelector('p');
para.addEventListener('click', updateName);
function updateName() {
var name = prompt('Enter a new name');
para.textContent = 'Player 1: ' + name;
}
</script>
</html>
I'm guessing I would have put <script src="js/script.js"></script>
at the bottom of the html page?
if not I get the error
'updateName' was used before it was defined. para.addEventListener('click', updateName);
'prompt' was used before it was defined. var name = prompt('Enter a new name');