Using the <script> element
<!doctype html> <html> <head> <script> var who = "George"; var yrs = 2; var mySentence = who + " has been writing script for " + yrs + " years."; </script> </head> <body> <script> document.write( mySentence ); </script> </body> </html>
var who = "George"; var yrs = 2; var mySentence = who + " has been writing script for " + yrs + " years.";
HTML element event attributes
Authors may use the many HTML event attributes to execute code directly in their HTML markup. Which is not best practice moving forward, but it works just fine when you need to use it.
<button onclick="alert('hello')">click me</button> <button onclick="alert('Bye'); window.close();">click me too</button>