how to give alert in javascript code example

Example 1: how to make an alert in html

<script>
  alert('this is an alert');
</script>

Example 2: how to send an alert in javascript

//you can either do this:

function mousePressed() {
	//you can have any message
  alert("I'm the best");
}

//or you can do this:

function keyPressed() {
	//you can do any key
  if (keyCode === UP_ARROW) {
  	//and any message
    alert(number = random(0, 500));
  }
}

//or you can do an (if) statement

if(x > width) {
 	alert("yay you did it");
}