you want to show alert box using javascript
. Try this code
html code
<button onclick="myFunction()">Button1</button>
<p id="test"></p>
Write javascript
in bottom in .phtml file
<script type="text/javascript">
function myFunction() {
document.getElementById("test").innerHTML;
alert("Right Alert Box");
console.log("Right Console Alert");
}
</script>
And Second You want to write code using require
method write this code
html code
<button name="my_btn" id="alert_btn">Button 2</button>
Js code
<script type="text/javascript">
require(['jquery'], function($) {
$('#alert_btn').click(function() {
alert("Right Alert Box2");
console.log("Right Console Alert2");
});
})
</script>
And we have write both code in .phtml file

And Last Output both button
Button 1:-

Button 2:-

Hope this help you
Thanks ...