A very simple way would be by using the alert API :
https://developer.mozilla.org/en-US/docs/Web/API/Window/alert
This way you can display a message to the user.
A very simple way would be by using the alert API :
https://developer.mozilla.org/en-US/docs/Web/API/Window/alert
This way you can display a message to the user.
I am wondering how I can make a particular area output some code but that code can only work in that particular area.
I am using HTML and Javascript to do this, and have tried one thing:
<div id="messageboard">
<script>
function levelUp() {
let playerLevel = 0;
playerLevel++;
console.log('You have reached level ' + playerLevel + '!');
</script>
</div>
It’s a bit confusing since the output console.log is part of a function and consequently I have had to put the function inside the divider as well.
If it will clear this whole thing up a bit, I will show the whole code:
<!DOCTYPE html>
<html>
<body>
<canvas>
<script type="text/javascript">
let characterAnimation = "Character before mining.jpg";
function levelUp() {
let playerLevel = 0;
playerLevel++;
console.log('You have reached level ' + playerLevel + '!');
}
function mining() {
const miningBlock = "Fast%20Typer/Mining%20Block.png";
}
addEventListener('keydown', function(event) {
if (event keyCode === 13, 16, 20, 32, 48, 49, 50, 51, 52, 53, 54, 55, 56, 9, 57, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 84, 85, 86, 87, 88, 89, 90, 107, 109, 110, 111, 186, 187, 188, 191, 220, 222, 221, 189) {
levelUp();
characterAnimation = "Character while mining";
}
})
characterAnimation = "Character before mining.jpg";
</script>
<div id="messageboard">
<script>
function levelUp() {
let playerLevel = 0;
playerLevel++;
console.log('You have reached level ' + playerLevel + '!');
</script>
</canvas>
And since it all has to run, I have to put it into the same code block but then I also have to put the levelUp function into the div so that it console.logs in the correct area.
Any help would be welcome.
š
console.log will log to the console, not to the div element.
Oh. Thanks. I’m basically a noob to coding. I kind of thought that it would print to the UI, I guess.
Iām voting to close this question because the markup is completely invalid.
Thanks. before you asked the question, I had made a div in the HTML and just left it like that. That really helped. š