This is a playground for JS dev.
Player 1: Name
const para = document.querySelector('#name-input');
para.addEventListener('click', updateName);
function updateName() {
const name = prompt('Enter a new name');
para.textContent = `Player 1: ${name}`;
}
...querySelector('#id')
the same as ...getElementById('id)
?People interact with a website by clicking and typing. However, the most fundament action is the mouse click. Which, the 'website' 'listens' for with event listers such as ...addEventListener('event', function)
.
<script></script>
tags immediately before the </body>
tag
<script>
...code...
</script>
</body>
<script></script>
tags immediately before the </head>
tag
<script>
document.addEventListener('DOMContentLoaded', () => {
...code...
});
</script>
</head>
</head>
tag <script src="/script.js" defer></script>
</head>
defer
attribute which accomplishes essentially the same thing.Welcome to our number guessing game! We have randomly picked a number from 1 to 100. Each time you guess, we'll tell you if it's correct, too low, or too high. Seems easy, right? The catch is, you only have 7 guesses!